//==============================================================================================
/**
 * @file	frontier_monitor.c
 * @brief	「バトルフロンティア」モニター
 * @author	Satoshi Nohara
 * @date	2007.12.6
 *
 * typeは0=SINGLEと考えています
 */
//==============================================================================================
#include "common.h"
#include "gflib/touchpanel.h"
#include "system/main.h"
#include "system/arc_tool.h"
#include "system/arc_util.h"
#include "system/clact_tool.h"
#include "system/brightness.h"
#include "system/wipe.h"
#include "system/snd_tool.h"
#include "system/pm_str.h"
#include "system/buflen.h"
#include "system/wordset.h"
#include "system/bmp_menu.h"
#include "system/window.h"
#include "system/fontproc.h"
#include "system/cursor_move.h"
#include "system/msg_ds_icon.h"

#include "savedata/config.h"
#include "savedata/frontier_savedata.h"
#include "savedata/frontier_ex.h"

#include "savedata/factory_savedata.h"
#include "savedata/stage_savedata.h"
#include "savedata/castle_savedata.h"
#include "savedata/roulette_savedata.h"
#include "savedata/b_tower.h"

#include "msgdata\msg.naix"					//NARC_msg_??_dat
#include "msgdata\msg_bf_seiseki.h"			//msg_??

#include "../field/fieldsys.h"				//scr_tool.hに必要
#include "../field/scr_tool.h"				//FactoryScr_GetWinRecordID
#include "../field/poketch/poketch_arc.h"	//ポケッチにあるボールの絵を使いまわし

#include "application/frontier_monitor.h"
#include "frontier_monitor_bmp.h"
#include "frontier_def.h"
#include "graphic/frontier_obj_def.h"
#include "graphic/frontier_bg_def.h"

#include "factory_def.h"
#include "stage_def.h"
#include "castle_def.h"
#include "roulette_def.h"

#include "application/zukanlist/zkn_gira.h"
#include "../application/zukanlist/zkn_data/zukan_data.naix"


//==============================================================================================
//
//	定義
//
//==============================================================================================
//シーケンス定義
enum {
	SEQ_GAME_INIT,											//初期化
	SEQ_GAME_START,											//ゲーム開始
	SEQ_GAME_END,											//終了
};

// 操作処理のシーケンス
enum {
	MAINSEQ_INIT = 0,				// 開始処理
	MAINSEQ_NORMAL_MAIN,			// 通常メイン
	MAINSEQ_STAGE_STR_INIT,			// ステージ五十音選択初期化
	MAINSEQ_STAGE_STR_SELECT,		// ステージ五十音選択
	MAINSEQ_STAGE_POKE_INIT,		// ステージポケモン選択初期化
	MAINSEQ_STAGE_POKE_SELECT,		// ステージポケモン選択
	MAINSEQ_STAGE_POKE_SEL_CHANGE,	// ステージポケモン選択ページ切り替え
	MAINSEQ_STAGE_RESULT_INIT,		// ステージ成績画面選択初期化
	MAINSEQ_STAGE_RESULT,			// ステージ成績画面
	MAINSEQ_BUTTON_ANM,				// ボタンアニメ
	MAINSEQ_END						// 終了
};

#define	FCOL_WHITE	( 15 )		// 文字色・白

// 文字カラー
#define	FCOL_N_WHITE	( GF_PRINTCOLOR_MAKE(FCOL_WHITE,FBMP_COL_BLK_SDW,FBMP_COL_NULL) )
#define	FCOL_N_BLACK	( GF_PRINTCOLOR_MAKE(FBMP_COL_BLACK,FBMP_COL_BLK_SDW,FBMP_COL_NULL) )
#define	FCOL_W_BLACK	( GF_PRINTCOLOR_MAKE(FBMP_COL_BLACK,FBMP_COL_BLK_SDW,FCOL_WHITE) )
#define	FCOL_TOUCH		( GF_PRINTCOLOR_MAKE(FCOL_WHITE,FBMP_COL_BLACK,FBMP_COL_NULL) )

// 文字列表示定義
enum {
	STRPRINT_MODE_LEFT = 0,	// 左詰
	STRPRINT_MODE_RIGHT,	// 右詰
	STRPRINT_MODE_CENTER,	// 中央
};

#define FRONTIER_MSG_BUF_SIZE		(800)//(1024)			//メッセージサイズ

// OBJ
enum {
	FM_OBJ_RET_BUTTON = 0,
	FM_OBJ_RET_CURSOR,
	FM_OBJ_MAX
};

#define	FM_SUB_ACTOR_DISTANCE	( 512*FX32_ONE )	// サブ画面のOBJ表示Y座標オフセット

#define	CLA_H_NONE	( CLACT_U_HEADER_DATA_NONE )	// セルアクターヘッダーデータなし

#define	CLACT_ID_COMMON		( 55500 )	// この画面で使用するセルアクターのID

// キャラリソースID
enum {
	CHR_ID_RET_BUTTON = CLACT_ID_COMMON,	//「もどる」ボタン
	CHR_ID_MAX = CHR_ID_RET_BUTTON - CLACT_ID_COMMON + 1
};
// パレットリソースID
enum {
	PAL_ID_RET_BUTTON = CLACT_ID_COMMON,	//「もどる」ボタン
	PAL_ID_MAX = PAL_ID_RET_BUTTON - CLACT_ID_COMMON + 1
};
// セルリソースID
enum {
	CEL_ID_RET_BUTTON = CLACT_ID_COMMON,	//「もどる」ボタン
	CEL_ID_MAX = CEL_ID_RET_BUTTON - CLACT_ID_COMMON + 1
};
// アニメリソースID
enum {
	ANM_ID_RET_BUTTON = CLACT_ID_COMMON,	//「もどる」ボタン
	ANM_ID_MAX = ANM_ID_RET_BUTTON - CLACT_ID_COMMON + 1
};

#define	PALSIZ_RET_BUTTON	( 2 )		// パレット数：「もどる」ボタン

// ボタンＯＢＪ表示座標
#define	OBJ_RET_BUTTON_PX	( 224 )
#define	OBJ_RET_BUTTON_PY	( 176 )

// ステージページ
enum {
	FM_STAGE_PAGE_RESULT = 0,	// 成績画面
	FM_STAGE_STR_SELECT,		// 五十音選択
	FM_STAGE_POKE_SELECT,		// ポケモン選択
};

// ボタンアニメモード
enum {
	BTN_ANM_MODE_OBJ = 0,
	BTN_ANM_MODE_BG,
};

#define	STAGE_STR_INPUT_MAX		( 44 )		// ステージの文字検索数


// 成績画面の文字列表示座標：ファクトリー
#define	FACTORY_TITLE_PX				( 0 )
#define	FACTORY_TYPE_PX					( 16*8 )

#define	FACTORY_LV50_PX					( 0 )
#define	FACTORY_LV50_CHG_PX				( 27*8 )

#define	FACTORY_LV50_NOW_PX				( 0 )
#define	FACTORY_LV50_NOW_WIN_PX			( 11*8 )
#define	FACTORY_LV50_NOW_WIN_STR_PX		( 19*8 )
#define	FACTORY_LV50_NOW_CHG_PX			( 24*8 )
#define	FACTORY_LV50_NOW_CHG_STR_PX		( 27*8 )

#define	FACTORY_LV50_BST_PX				( 0 )
#define	FACTORY_LV50_BST_WIN_PX			( 11*8 )
#define	FACTORY_LV50_BST_WIN_STR_PX		( 19*8 )
#define	FACTORY_LV50_BST_CHG_PX			( 24*8 )
#define	FACTORY_LV50_BST_CHG_STR_PX		( 27*8 )

#define	FACTORY_LV100_PX				( 0 )
#define	FACTORY_LV100_CHG_PX			( 27*8 )

#define	FACTORY_LV100_NOW_PX			( 0 )
#define	FACTORY_LV100_NOW_WIN_PX		( 11*8 )
#define	FACTORY_LV100_NOW_WIN_STR_PX	( 19*8 )
#define	FACTORY_LV100_NOW_CHG_PX		( 24*8 )
#define	FACTORY_LV100_NOW_CHG_STR_PX	( 27*8 )

#define	FACTORY_LV100_BST_PX			( 0 )
#define	FACTORY_LV100_BST_WIN_PX		( 11*8 )
#define	FACTORY_LV100_BST_WIN_STR_PX	( 19*8 )
#define	FACTORY_LV100_BST_CHG_PX		( 24*8 )
#define	FACTORY_LV100_BST_CHG_STR_PX	( 27*8 )

// 成績画面の文字列表示座標：ステージ
#define	STAGE_TITLE_PX			( 0 )
#define	STAGE_TYPE_PX			( 13*8 )

#define	STAGE_POKE_PX			( 0 )

#define	STAGE_NOW_PX			( 0 )
#define	STAGE_NOW_WIN_PX		( 11*8 )
#define	STAGE_NOW_WIN_STR_PX	( 19*8 )

#define	STAGE_BST_PX			( 0 )
#define	STAGE_BST_WIN_PX		( 11*8 )
#define	STAGE_BST_WIN_STR_PX	( 19*8 )

// 成績画面の文字列表示座標：キャッスル
#define	CASTLE_TITLE_PX				( 0 )
#define	CASTLE_TYPE_PX				( 16*8 )

#define	CASTLE_POINT_PX				( 14*8 )

#define	CASTLE_NOW_PX				( 0 )
#define	CASTLE_NOW_ROOM_PX			( 11*8 )
#define	CASTLE_NOW_ROOM_STR_PX		( 20*8 )
#define	CASTLE_NOW_POINT_PX			( 25*8 )
#define	CASTLE_NOW_POINT_STR_PX		( 27*8 )

#define	CASTLE_BST_PX				( 0 )
#define	CASTLE_BST_ROOM_PX			( 11*8 )
#define	CASTLE_BST_ROOM_STR_PX		( 20*8 )
#define	CASTLE_BST_POINT_PX			( 25*8 )
#define	CASTLE_BST_POINT_STR_PX		( 27*8 )

// 成績画面の文字列表示座標：ルーレット
#define	ROULETTE_TITLE_PX		( 0 )
#define	ROULETTE_TYPE_PX		( 14*8 )

#define	ROULETTE_NOW_PX			( 0 )
#define	ROULETTE_NOW_WIN_PX		( 11*8 )
#define	ROULETTE_NOW_WIN_STR_PX	( 23*8 )

#define	ROULETTE_BST_PX			( 0 )
#define	ROULETTE_BST_WIN_PX		( 11*8 )
#define	ROULETTE_BST_WIN_STR_PX	( 23*8 )

// 成績画面の文字列表示座標：タワー
#define	TOWER_TITLE_PX				( 0 )
#define	TOWER_TYPE_PX				( 11*8 )

#define	TOWER_S_NOW_PX				( 0 )
#define	TOWER_S_NOW_WIN_PX			( 11*8 )
#define	TOWER_S_NOW_WIN_STR_PX		( 19*8 )

#define	TOWER_S_BST_PX				( 0 )
#define	TOWER_S_BST_WIN_PX			( 11*8 )
#define	TOWER_S_BST_WIN_STR_PX		( 19*8 )

#define	TOWER_M_TR_TITLE_PX			( 0 )

#define	TOWER_M_TR_NOW_PX			( 0 )
#define	TOWER_M_TR_NOW_WIN_PX		( 11*8 )
#define	TOWER_M_TR_NOW_WIN_STR_PX	( 19*8 )

#define	TOWER_M_TR_BST_PX			( 0 )
#define	TOWER_M_TR_BST_WIN_PX		( 11*8 )
#define	TOWER_M_TR_BST_WIN_STR_PX	( 19*8 )

#define	TOWER_M_FR_TITLE_PX			( 0 )

#define	TOWER_M_FR_NOW_PX			( 0 )
#define	TOWER_M_FR_NOW_WIN_PX		( 11*8 )
#define	TOWER_M_FR_NOW_WIN_STR_PX	( 19*8 )

#define	TOWER_M_FR_BST_PX			( 0 )
#define	TOWER_M_FR_BST_WIN_PX		( 11*8 )
#define	TOWER_M_FR_BST_WIN_STR_PX	( 19*8 )


// ステージ五十音入力ページ・イニシャル表示定義
#define	STAGE_STR_INPUT_PX		( 8 )		// Ｘ座標
#define	STAGE_STR_INPUT_PY		( 0 )		// Ｙ座標
#define	STAGE_STR_INPUT_SX		( 24 )		// Ｘ表示間隔
#define	STAGE_STR_INPUT_SY		( 24 )		// Ｙ表示間隔
#define	STAGE_STR_INPUT_Y_MAX	( 5 )		// Ｙ表示数

// ステージ五十音入力ページ・タッチ座標作成定義
#define	SEARCH_NAME_PX		( 8 )
#define	SEARCH_NAME_PY		( 40 )
#define	SEARCH_NAME_SX		( 16 )
#define	SEARCH_NAME_SY		( 16 )
#define	SEARCH_NAME_SPACE_X	( STAGE_STR_INPUT_SX )
#define	SEARCH_NAME_SPACE_Y	( STAGE_STR_INPUT_SY )
#define	SEARCH_NAME_MY		( STAGE_STR_INPUT_Y_MAX )
#define	SEARCH_NAME_LX(a)	( SEARCH_NAME_PX + a / SEARCH_NAME_MY * SEARCH_NAME_SPACE_X )
#define	SEARCH_NAME_RX(a)	( SEARCH_NAME_LX(a) + SEARCH_NAME_SX - 1 )
#define	SEARCH_NAME_UY(a)	( SEARCH_NAME_PY + a % SEARCH_NAME_MY * SEARCH_NAME_SPACE_Y )
#define	SEARCH_NAME_DY(a)	( SEARCH_NAME_UY(a) + SEARCH_NAME_SY - 1 )
#define	SEARCH_NAME_CUR_X(a)	( SEARCH_NAME_LX(a) + SEARCH_NAME_SX / 2 )
#define	SEARCH_NAME_CUR_Y(a)	( SEARCH_NAME_UY(a) + SEARCH_NAME_SY / 2 )

#define	STAGE_INPUT_RET_CMWK_ID		( 44 )	// ステージ五十音入力ページ・「もどる」ボタンＩＤ

// ステージポケモン選択ページ・ボタン座標
#define	STAGE_POKESEL_BUTTON_PX		( 38 )
#define	STAGE_POKESEL_BUTTON_PY		( 37 )
#define	STAGE_POKESEL_BUTTON_SX		( 9 )
#define	STAGE_POKESEL_BUTTON_SY		( 2 )
#define	STAGE_POKESEL_BUTTON_SPC_X	( 13 )
#define	STAGE_POKESEL_BUTTON_SPC_Y	( 4 )

// ステージポケモン選択ページ・ページ表示座標
#define	STAGE_POKEPAGE_NOW_PX	( 8 )
#define	STAGE_POKEPAGE_SRA_PX	( 16 )
#define	STAGE_POKEPAGE_MAX_PX	( 32 )

#define	STAGE_POKESEL_MAX	( 8 )	// ステージポケモン選択ページ・ポケモン表示数

#define	SUB_MAGWIN_CGX	( 1024 - TALK_WIN_CGX_SIZ )		// メッセージウィンドウキャラ位置


//==============================================================================================
//
//	構造体宣言
//
//==============================================================================================
// ステージのリストデータ
typedef struct {
	u16 * list;
	u32	max;
}STAGE_POKELIST;

// 成績画面ワーク
typedef struct{
	PROC* proc;											//PROCへのポインタ

	u8	sub_seq;										//シーケンス
	u8	next_seq;
	u8	type;											//シングル、ダブル、マルチ、wifiマルチ
	u8	fr_no;											//施設ナンバー

	u16 monsno;
	u16 dummy2;

	GF_BGL_INI*	bgl;									//BGLへのポインタ
	//GF_BGL_BMPWIN bmpwin[FRONTIER_MONITOR_BMPWIN_MAX];	//BMPウィンドウデータ
	GF_BGL_BMPWIN bmpwin[32];	//BMPウィンドウデータ

	MSGDATA_MANAGER* msgman;							//メッセージマネージャー
	WORDSET* wordset;									//単語セット
	STRBUF* msg_buf;									//メッセージバッファポインタ

	PALETTE_FADE_PTR pfd;								//パレットフェード

	const CONFIG* config;								//コンフィグポインタ
	SAVEDATA* sv;										//セーブデータポインタ
	FRONTIER_SAVEWORK* f_sv;

// ↓金銀追加分
	// OBJ関連
	CATS_SYS_PTR	csp;
	CATS_RES_PTR	crp;
	CATS_ACT_PTR	cap[FM_OBJ_MAX];

	GF_BGL_BMPWIN	ret_win;	// BMPウィンドウデータ

	u8	btn_mode:1;
	u8	btn_id:7;			// OBJ = ID, BG = FRM
	u8	btn_pal1:4;
	u8	btn_pal2:4;
	u8	btn_seq;
	u8	btn_cnt;
	u8	btn_px;			// BGのみ
	u8	btn_py;
	u8	btn_sx;
	u8	btn_sy;

	CURSOR_MOVE_WORK * cmwk;	// カーソル移動ワーク

	u16	stpos;
	u16	stmons;
	s8	stscr;
	s8	stscr_max;
	u16	stswap;

	STAGE_POKELIST	st_pokelist[STAGE_STR_INPUT_MAX];
	void * diwk;

	u16	starrow[4*4*3];		// 矢印スクリーン

}FRONTIER_MONITOR_WORK;


//==============================================================================================
//
//	プロトタイプ宣言
//
//==============================================================================================
//PROC
PROC_RESULT FrontierMonitorProc_Init( PROC * proc, int * seq );
PROC_RESULT FrontierMonitorProc_Main( PROC * proc, int * seq );
PROC_RESULT FrontierMonitorProc_End( PROC * proc, int * seq );

//シーケンス
static BOOL Seq_GameInit( FRONTIER_MONITOR_WORK* wk );
static BOOL Seq_GameStart( FRONTIER_MONITOR_WORK* wk );
static BOOL Seq_GameEnd( FRONTIER_MONITOR_WORK* wk );

//設定
static void VBlankFunc( void * work );
static void SetVramBank(void);
static void SetBgHeader( GF_BGL_INI * ini );

//共通初期化、終了
static void Frontier_BgInit( FRONTIER_MONITOR_WORK* wk );
static void Frontier_BgExit( GF_BGL_INI * ini );

//ツール
static void NextSeq( FRONTIER_MONITOR_WORK* wk, int* seq, int next );
static int KeyCheck( int key );
static u8 GetBmpNo( u8 fr_no );

//BGグラフィックデータ
static void Frontier_SetMainBgGraphic( FRONTIER_MONITOR_WORK * wk, u32 frm  );
//static void Frontier_SetMainBgPalette( void );
static void Frontier_SetSubBgGraphic( FRONTIER_MONITOR_WORK * wk, u32 frm  );

//メッセージ関連
static void SetNumber( FRONTIER_MONITOR_WORK* wk, u32 bufID, s32 number );
static void Frontier_Write( FRONTIER_MONITOR_WORK* wk );

//ファクトリー
static void Factory_SetLv50Info( FRONTIER_MONITOR_WORK* wk );
static void Factory_SetLv100Info( FRONTIER_MONITOR_WORK* wk );
static u32 Factory_GetMsg( FRONTIER_MONITOR_WORK* wk, u8 level );

//ステージ
static void Stage_SetInfo( FRONTIER_MONITOR_WORK* wk );
static u32 Stage_GetMsg( FRONTIER_MONITOR_WORK* wk );
static void FrontierMonitor_PokeName( FRONTIER_MONITOR_WORK* wk, u16 mons );

//キャッスル
static void Castle_SetInfo( FRONTIER_MONITOR_WORK* wk );
static u32 Castle_GetMsg( FRONTIER_MONITOR_WORK* wk );

//ルーレット
static void Roulette_SetInfo( FRONTIER_MONITOR_WORK* wk );
static u32 Roulette_GetMsg( FRONTIER_MONITOR_WORK* wk );

//タワー
static void Tower_SetInfoSingleDouble( FRONTIER_MONITOR_WORK* wk );
static void Tower_SetInfoMulti( FRONTIER_MONITOR_WORK* wk );
static u32 Tower_GetMsg( FRONTIER_MONITOR_WORK* wk, u8 type );

static void RetButtonStrPut( FRONTIER_MONITOR_WORK * wk );

static void ObjInit( FRONTIER_MONITOR_WORK * wk );
static void ObjExit( FRONTIER_MONITOR_WORK * wk );
static void ObjAnmMain( FRONTIER_MONITOR_WORK * wk );
//static void ObjAnmSet( FRONTIER_MONITOR_WORK * wk, u32 id, u32 anm );
//static BOOL ObjAnmChack( FRONTIER_MONITOR_WORK * wk, u32 id );
static void RetButtonAnmSet( FRONTIER_MONITOR_WORK * wk );
static BOOL ButtonAnmMain( FRONTIER_MONITOR_WORK * wk );

static BOOL StageCheck( FRONTIER_MONITOR_WORK * wk );
static void StageInit( FRONTIER_MONITOR_WORK * wk );
static void StagePageChange( FRONTIER_MONITOR_WORK * wk, u32 page );
static void StageInputStrWrite( FRONTIER_MONITOR_WORK * wk );
static void StageInputStrCursorMoveInit( FRONTIER_MONITOR_WORK * wk );
static void CursorMoveWorkExit( FRONTIER_MONITOR_WORK * wk );
static void CursorMoveCallBack_Dummy( void * work, int now_pos, int old_pos );
static u8 StageStrSelectMain( FRONTIER_MONITOR_WORK * wk );
static void StagePokeSelCursorMoveInit( FRONTIER_MONITOR_WORK * wk );
static u8 StagePokeSelMain( FRONTIER_MONITOR_WORK * wk );
static u8 StagePokeSelPageChange( FRONTIER_MONITOR_WORK * wk );
static void StagePokeListMake( FRONTIER_MONITOR_WORK * wk );
static void StagePokeListFree( FRONTIER_MONITOR_WORK * wk );
static void StageStrInputButtonInit( FRONTIER_MONITOR_WORK * wk );
static void StagePokeNamePut( FRONTIER_MONITOR_WORK * wk );
static void StagePokeNameOff( FRONTIER_MONITOR_WORK * wk );
static void StagePokeInitialPut( FRONTIER_MONITOR_WORK * wk );
static void StagePokePagePut( FRONTIER_MONITOR_WORK * wk );
static void StageArrowChange( FRONTIER_MONITOR_WORK * wk );
static void StageResultCursorInit( FRONTIER_MONITOR_WORK * wk );
static void StageResultBmpPut( FRONTIER_MONITOR_WORK * wk );
static void StageResultBmpOff( FRONTIER_MONITOR_WORK * wk );
static void StageMsgWinLoad( FRONTIER_MONITOR_WORK * wk );
static void StageMsgPut( FRONTIER_MONITOR_WORK * wk );
static void StageMsgOff( FRONTIER_MONITOR_WORK * wk );
static void StageInputStrCallBack_Move( void * work, int now_pos, int old_pos );
static void StageInputStrCallBack_Touch( void * work, int now_pos, int old_pos );
static void StagePokeSelCallBack_Move( void * work, int now_pos, int old_pos );
static void StagePokeSelCallBack_Touch( void * work, int now_pos, int old_pos );


//============================================================================================
//	グローバル
//============================================================================================
// ＯＢＪデータ
static const TCATS_OBJECT_ADD_PARAM_S ClaAddPrm[] =
{
	{	//「もどる」ボタン
		OBJ_RET_BUTTON_PX, OBJ_RET_BUTTON_PY, 0,
		0, 10, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_RET_BUTTON, PAL_ID_RET_BUTTON, CEL_ID_RET_BUTTON, ANM_ID_RET_BUTTON, CLA_H_NONE, CLA_H_NONE },
		1, 0
	},
	{	//「もどる」ボタンカーソル
		OBJ_RET_BUTTON_PX, OBJ_RET_BUTTON_PY, 0,
		1, 0, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_RET_BUTTON, PAL_ID_RET_BUTTON, CEL_ID_RET_BUTTON, ANM_ID_RET_BUTTON, CLA_H_NONE, CLA_H_NONE },
		0, 0
	},
};

static const TP_HIT_TBL EndHitTbl = { 164, 187, 193, 254 };		//「もどる」ボタンタッチ座標

// ステージ五十音入力ページ用・頭文字表示位置テーブル
static const u8 InitialStrPosTbl[] = {
	 0,  1,  2,  3,  4,		// ア
	 5,  6,  7,  8,  9,		// カ
	10, 11, 12, 13, 14,		// サ
	15, 16, 17, 18, 19,		// タ
	20, 21, 22, 23, 24,		// ナ
	25, 26, 27, 28, 29,		// ハ
	30, 31, 32, 33, 34,		// マ
	35,     37,     39,		// ヤ
	40, 41, 42, 43, 44,		// ラ
	45,						// ワ
};

// ステージ五十音入力ページ・タッチ座標テーブル
static const RECT_HIT_TBL SearchNameHitTbl[] =
{
	{ SEARCH_NAME_UY(0), SEARCH_NAME_DY(0), SEARCH_NAME_LX(0), SEARCH_NAME_RX(0) },	// ア
	{ SEARCH_NAME_UY(1), SEARCH_NAME_DY(1), SEARCH_NAME_LX(1), SEARCH_NAME_RX(1) },
	{ SEARCH_NAME_UY(2), SEARCH_NAME_DY(2), SEARCH_NAME_LX(2), SEARCH_NAME_RX(2) },
	{ SEARCH_NAME_UY(3), SEARCH_NAME_DY(3), SEARCH_NAME_LX(3), SEARCH_NAME_RX(3) },
	{ SEARCH_NAME_UY(4), SEARCH_NAME_DY(4), SEARCH_NAME_LX(4), SEARCH_NAME_RX(4) },

	{ SEARCH_NAME_UY(5), SEARCH_NAME_DY(5), SEARCH_NAME_LX(5), SEARCH_NAME_RX(5) },	// カ
	{ SEARCH_NAME_UY(6), SEARCH_NAME_DY(6), SEARCH_NAME_LX(6), SEARCH_NAME_RX(6) },
	{ SEARCH_NAME_UY(7), SEARCH_NAME_DY(7), SEARCH_NAME_LX(7), SEARCH_NAME_RX(7) },
	{ SEARCH_NAME_UY(8), SEARCH_NAME_DY(8), SEARCH_NAME_LX(8), SEARCH_NAME_RX(8) },
	{ SEARCH_NAME_UY(9), SEARCH_NAME_DY(9), SEARCH_NAME_LX(9), SEARCH_NAME_RX(9) },

	{ SEARCH_NAME_UY(10), SEARCH_NAME_DY(10), SEARCH_NAME_LX(10), SEARCH_NAME_RX(10) },	// サ
	{ SEARCH_NAME_UY(11), SEARCH_NAME_DY(11), SEARCH_NAME_LX(11), SEARCH_NAME_RX(11) },
	{ SEARCH_NAME_UY(12), SEARCH_NAME_DY(12), SEARCH_NAME_LX(12), SEARCH_NAME_RX(12) },
	{ SEARCH_NAME_UY(13), SEARCH_NAME_DY(13), SEARCH_NAME_LX(13), SEARCH_NAME_RX(13) },
	{ SEARCH_NAME_UY(14), SEARCH_NAME_DY(14), SEARCH_NAME_LX(14), SEARCH_NAME_RX(14) },

	{ SEARCH_NAME_UY(15), SEARCH_NAME_DY(15), SEARCH_NAME_LX(15), SEARCH_NAME_RX(15) },	// タ
	{ SEARCH_NAME_UY(16), SEARCH_NAME_DY(16), SEARCH_NAME_LX(16), SEARCH_NAME_RX(16) },
	{ SEARCH_NAME_UY(17), SEARCH_NAME_DY(17), SEARCH_NAME_LX(17), SEARCH_NAME_RX(17) },
	{ SEARCH_NAME_UY(18), SEARCH_NAME_DY(18), SEARCH_NAME_LX(18), SEARCH_NAME_RX(18) },
	{ SEARCH_NAME_UY(19), SEARCH_NAME_DY(19), SEARCH_NAME_LX(19), SEARCH_NAME_RX(19) },

	{ SEARCH_NAME_UY(20), SEARCH_NAME_DY(20), SEARCH_NAME_LX(20), SEARCH_NAME_RX(20) },	// ナ
	{ SEARCH_NAME_UY(21), SEARCH_NAME_DY(21), SEARCH_NAME_LX(21), SEARCH_NAME_RX(21) },
	{ SEARCH_NAME_UY(22), SEARCH_NAME_DY(22), SEARCH_NAME_LX(22), SEARCH_NAME_RX(22) },
	{ SEARCH_NAME_UY(23), SEARCH_NAME_DY(23), SEARCH_NAME_LX(23), SEARCH_NAME_RX(23) },
	{ SEARCH_NAME_UY(24), SEARCH_NAME_DY(24), SEARCH_NAME_LX(24), SEARCH_NAME_RX(24) },

	{ SEARCH_NAME_UY(25), SEARCH_NAME_DY(25), SEARCH_NAME_LX(25), SEARCH_NAME_RX(25) },	// ハ
	{ SEARCH_NAME_UY(26), SEARCH_NAME_DY(26), SEARCH_NAME_LX(26), SEARCH_NAME_RX(26) },
	{ SEARCH_NAME_UY(27), SEARCH_NAME_DY(27), SEARCH_NAME_LX(27), SEARCH_NAME_RX(27) },
	{ SEARCH_NAME_UY(28), SEARCH_NAME_DY(28), SEARCH_NAME_LX(28), SEARCH_NAME_RX(28) },
	{ SEARCH_NAME_UY(29), SEARCH_NAME_DY(29), SEARCH_NAME_LX(29), SEARCH_NAME_RX(29) },

	{ SEARCH_NAME_UY(30), SEARCH_NAME_DY(30), SEARCH_NAME_LX(30), SEARCH_NAME_RX(30) },	// マ
	{ SEARCH_NAME_UY(31), SEARCH_NAME_DY(31), SEARCH_NAME_LX(31), SEARCH_NAME_RX(31) },
	{ SEARCH_NAME_UY(32), SEARCH_NAME_DY(32), SEARCH_NAME_LX(32), SEARCH_NAME_RX(32) },
	{ SEARCH_NAME_UY(33), SEARCH_NAME_DY(33), SEARCH_NAME_LX(33), SEARCH_NAME_RX(33) },
	{ SEARCH_NAME_UY(34), SEARCH_NAME_DY(34), SEARCH_NAME_LX(34), SEARCH_NAME_RX(34) },

	{ SEARCH_NAME_UY(35), SEARCH_NAME_DY(35), SEARCH_NAME_LX(35), SEARCH_NAME_RX(35) },	// 35: ヤ
	{ SEARCH_NAME_UY(37), SEARCH_NAME_DY(37), SEARCH_NAME_LX(37), SEARCH_NAME_RX(37) },	// 36: ユ
	{ SEARCH_NAME_UY(39), SEARCH_NAME_DY(39), SEARCH_NAME_LX(39), SEARCH_NAME_RX(39) },	// 37: ヨ

	{ SEARCH_NAME_UY(40), SEARCH_NAME_DY(40), SEARCH_NAME_LX(40), SEARCH_NAME_RX(40) },	// 38: ラ
	{ SEARCH_NAME_UY(41), SEARCH_NAME_DY(41), SEARCH_NAME_LX(41), SEARCH_NAME_RX(41) },
	{ SEARCH_NAME_UY(42), SEARCH_NAME_DY(42), SEARCH_NAME_LX(42), SEARCH_NAME_RX(42) },
	{ SEARCH_NAME_UY(43), SEARCH_NAME_DY(43), SEARCH_NAME_LX(43), SEARCH_NAME_RX(43) },
	{ SEARCH_NAME_UY(44), SEARCH_NAME_DY(44), SEARCH_NAME_LX(44), SEARCH_NAME_RX(44) },

	{ SEARCH_NAME_UY(45), SEARCH_NAME_DY(45), SEARCH_NAME_LX(45), SEARCH_NAME_RX(45) },	// 43: ワ

	{ 164, 187, 193, 254 },		// 44: もどる

	{ RECT_HIT_END, 0, 0, 0 }
};
// ステージ五十音入力ページ・キー動作テーブル
static const POINTER_WORK SearchNameKeyTbl[] =
{
	{ SEARCH_NAME_CUR_X(0),SEARCH_NAME_CUR_Y(0),0,0,	0,  1, 0, 5 },		// ア
	{ SEARCH_NAME_CUR_X(1),SEARCH_NAME_CUR_Y(1),0,0,	0,  2, 1, 6 },
	{ SEARCH_NAME_CUR_X(2),SEARCH_NAME_CUR_Y(2),0,0,	1,  3, 2, 7 },
	{ SEARCH_NAME_CUR_X(3),SEARCH_NAME_CUR_Y(3),0,0,	2,  4, 3, 8 },
	{ SEARCH_NAME_CUR_X(4),SEARCH_NAME_CUR_Y(4),0,0,	3, 44, 4, 9 },

	{ SEARCH_NAME_CUR_X(5),SEARCH_NAME_CUR_Y(5),0,0,	5,  6, 0, 10 },		// カ
	{ SEARCH_NAME_CUR_X(6),SEARCH_NAME_CUR_Y(6),0,0,	5,  7, 1, 11 },
	{ SEARCH_NAME_CUR_X(7),SEARCH_NAME_CUR_Y(7),0,0,	6,  8, 2, 12 },
	{ SEARCH_NAME_CUR_X(8),SEARCH_NAME_CUR_Y(8),0,0,	7,  9, 3, 13 },
	{ SEARCH_NAME_CUR_X(9),SEARCH_NAME_CUR_Y(9),0,0,	8, 44, 4, 14 },

	{ SEARCH_NAME_CUR_X(10),SEARCH_NAME_CUR_Y(10),0,0,	10, 11, 5, 15 },	// サ
	{ SEARCH_NAME_CUR_X(11),SEARCH_NAME_CUR_Y(11),0,0,	10, 12, 6, 16 },
	{ SEARCH_NAME_CUR_X(12),SEARCH_NAME_CUR_Y(12),0,0,	11, 13, 7, 17 },
	{ SEARCH_NAME_CUR_X(13),SEARCH_NAME_CUR_Y(13),0,0,	12, 14, 8, 18 },
	{ SEARCH_NAME_CUR_X(14),SEARCH_NAME_CUR_Y(14),0,0,	13, 44, 9, 19 },

	{ SEARCH_NAME_CUR_X(15),SEARCH_NAME_CUR_Y(15),0,0,	15, 16, 10, 20 },	// タ
	{ SEARCH_NAME_CUR_X(16),SEARCH_NAME_CUR_Y(16),0,0,	15, 17, 11, 21 },
	{ SEARCH_NAME_CUR_X(17),SEARCH_NAME_CUR_Y(17),0,0,	16, 18, 12, 22 },
	{ SEARCH_NAME_CUR_X(18),SEARCH_NAME_CUR_Y(18),0,0,	17, 19, 13, 23 },
	{ SEARCH_NAME_CUR_X(19),SEARCH_NAME_CUR_Y(19),0,0,	18, 44, 14, 24 },

	{ SEARCH_NAME_CUR_X(20),SEARCH_NAME_CUR_Y(20),0,0,	20, 21, 15, 25 },	// ナ
	{ SEARCH_NAME_CUR_X(21),SEARCH_NAME_CUR_Y(21),0,0,	20, 22, 16, 26 },
	{ SEARCH_NAME_CUR_X(22),SEARCH_NAME_CUR_Y(22),0,0,	21, 23, 17, 27 },
	{ SEARCH_NAME_CUR_X(23),SEARCH_NAME_CUR_Y(23),0,0,	22, 24, 18, 28 },
	{ SEARCH_NAME_CUR_X(24),SEARCH_NAME_CUR_Y(24),0,0,	23, 44, 19, 29 },

	{ SEARCH_NAME_CUR_X(25),SEARCH_NAME_CUR_Y(25),0,0,	25, 26, 20, 30 },	// ハ
	{ SEARCH_NAME_CUR_X(26),SEARCH_NAME_CUR_Y(26),0,0,	25, 27, 21, 31 },
	{ SEARCH_NAME_CUR_X(27),SEARCH_NAME_CUR_Y(27),0,0,	26, 28, 22, 32 },
	{ SEARCH_NAME_CUR_X(28),SEARCH_NAME_CUR_Y(28),0,0,	27, 29, 23, 33 },
	{ SEARCH_NAME_CUR_X(29),SEARCH_NAME_CUR_Y(29),0,0,	28, 44, 24, 34 },

	{ SEARCH_NAME_CUR_X(30),SEARCH_NAME_CUR_Y(30),0,0,	30, 31, 25, 35 },	// マ
	{ SEARCH_NAME_CUR_X(31),SEARCH_NAME_CUR_Y(31),0,0,	30, 32, 26, 39 },
	{ SEARCH_NAME_CUR_X(32),SEARCH_NAME_CUR_Y(32),0,0,	31, 33, 27, 36 },
	{ SEARCH_NAME_CUR_X(33),SEARCH_NAME_CUR_Y(33),0,0,	32, 34, 28, 41 },
	{ SEARCH_NAME_CUR_X(34),SEARCH_NAME_CUR_Y(34),0,0,	33, 44, 29, 37 },

	{ SEARCH_NAME_CUR_X(35),SEARCH_NAME_CUR_Y(35),0,0,	35, 36, 30, 38 },	// ヤ
	{ SEARCH_NAME_CUR_X(37),SEARCH_NAME_CUR_Y(37),0,0,	35, 37, 32, 40 },
	{ SEARCH_NAME_CUR_X(39),SEARCH_NAME_CUR_Y(39),0,0,	36, 44, 34, 42 },

	{ SEARCH_NAME_CUR_X(40),SEARCH_NAME_CUR_Y(40),0,0,	38, 39, 35, 43 },	// ラ
	{ SEARCH_NAME_CUR_X(41),SEARCH_NAME_CUR_Y(41),0,0,	38, 40, 31, 39 },
	{ SEARCH_NAME_CUR_X(42),SEARCH_NAME_CUR_Y(42),0,0,	39, 41, 36, 40 },
	{ SEARCH_NAME_CUR_X(43),SEARCH_NAME_CUR_Y(43),0,0,	40, 42, 33, 41 },
	{ SEARCH_NAME_CUR_X(44),SEARCH_NAME_CUR_Y(44),0,0,	41, 44, 37, 42 },

	{ SEARCH_NAME_CUR_X(45),SEARCH_NAME_CUR_Y(45),0,0,	43, 44, 38, 43 },	// ワ

	{ OBJ_RET_BUTTON_PX, OBJ_RET_BUTTON_PY, 0, 0,	CURSORMOVE_RETBIT|4, 44, 44, 44 },		// 44: もどる
};
// ステージ五十音入力ページ・カーソル動作コールバック関数テーブル
static const CURSORMOVE_CALLBACK SearchNameCallBack = {
	CursorMoveCallBack_Dummy,			// on,
	CursorMoveCallBack_Dummy,			// off
	StageInputStrCallBack_Move,			// move,
	StageInputStrCallBack_Touch,		// touch,
};

// ステージポケモン選択ページ・タッチ座標テーブル
static const RECT_HIT_TBL StagePokeSelHitTbl[] =
{
	{  32,  63,  40, 127 },
	{  32,  63, 144, 231 },
	{  64,  95,  40, 127 },
	{  64,  95, 144, 231 },
	{  96, 127,  40, 127 },
	{  96, 127, 144, 231 },
	{ 128, 159,  40, 127 },
	{ 128, 159, 144, 231 },

	{ 164, 187, 193, 254 },		// 8: もどる

	{ RECT_HIT_END, 0, 0, 0 }
};
// ステージポケモン選択ページ・キー動作テーブル
static const POINTER_WORK StagePokeSelKeyTbl[] =
{
	{  84,  48, 0, 0,	0, 2, 0, 1 },
	{ 188,  48, 0, 0,	1, 3, 0, 1 },
	{  84,  80, 0, 0,	0, 4, 2, 3 },
	{ 188,  80, 0, 0,	1, 5, 2, 3 },
	{  84, 112, 0, 0,	2, 6, 4, 5 },
	{ 188, 112, 0, 0,	3, 7, 4, 5 },
	{  84, 144, 0, 0,	4, 8, 6, 7 },
	{ 188, 144, 0, 0,	5, 8, 6, 7 },

	{ OBJ_RET_BUTTON_PX, OBJ_RET_BUTTON_PY, 0, 0,	CURSORMOVE_RETBIT|7, 8, 8, 8 },		// 8: もどる
};
// ステージポケモン選択ページ・カーソル動作コールバック関数テーブル
static const CURSORMOVE_CALLBACK StagePokeSelCallBack = {
	CursorMoveCallBack_Dummy,			// on
	CursorMoveCallBack_Dummy,			// off
	StagePokeSelCallBack_Move,			// move
	StagePokeSelCallBack_Touch,			// touch
};

// ステージポケモン選択ページ・スクロール矢印のタッチ座標テーブル
static const RECT_HIT_TBL StagePokeSelArrowHitTbl[] =
{
	{ 162, 189, 18, 45 },		// 左
	{ 162, 189, 50, 77 },		// 右
	{ RECT_HIT_END, 0, 0, 0 }
};








//==============================================================================================
//
//	PROC
//
//==============================================================================================

//--------------------------------------------------------------
/**
 * @brief	プロセス関数：初期化
 *
 * @param	proc	プロセスデータ
 * @param	seq		シーケンス
 *
 * @return	"処理状況"
 */
//--------------------------------------------------------------
PROC_RESULT FrontierMonitorProc_Init( PROC * proc, int * seq )
{
	int i;
	FRONTIER_MONITOR_WORK* wk;
	FRONTIER_MONITOR_CALL* bfm_call;

	sys_VBlankFuncChange( NULL, NULL );					//VBlankセット
	sys_HBlankIntrSet( NULL,NULL );						//HBlankセット
	GF_Disp_GX_VisibleControlInit();
	GF_Disp_GXS_VisibleControlInit();
	GX_SetVisiblePlane( 0 );
	GXS_SetVisiblePlane( 0 );
	// サブ画面をメインに
	GX_SetDispSelect( GX_DISP_SELECT_SUB_MAIN );

	sys_CreateHeap( HEAPID_BASE_APP, HEAPID_FRONTIER_MONITOR, 0x30000 );

	wk = PROC_AllocWork( proc, sizeof(FRONTIER_MONITOR_WORK), HEAPID_FRONTIER_MONITOR );
	memset( wk, 0, sizeof(FRONTIER_MONITOR_WORK) );

	wk->proc	= proc;
	wk->bgl		= GF_BGL_BglIniAlloc( HEAPID_FRONTIER_MONITOR );
	bfm_call	= (FRONTIER_MONITOR_CALL*)PROC_GetParentWork( proc );
	wk->sv		= bfm_call->sv;
	wk->f_sv	= SaveData_GetFrontier( wk->sv );
	wk->type	= bfm_call->type;
	wk->fr_no	= bfm_call->fr_no;
	wk->monsno	= bfm_call->monsno;
	wk->config	= SaveData_GetConfig( wk->sv );			//コンフィグポインタを取得

	FontProc_LoadFont( FONT_TOUCH, HEAPID_FRONTIER_MONITOR );

	Frontier_BgInit( wk );								//BG初期化

	//メッセージデータマネージャー作成
	wk->msgman = MSGMAN_Create( MSGMAN_TYPE_DIRECT, ARC_MSG,
								NARC_msg_bf_seiseki_dat, HEAPID_FRONTIER_MONITOR );

	wk->wordset = WORDSET_Create( HEAPID_FRONTIER_MONITOR );
	wk->msg_buf = STRBUF_Create( FRONTIER_MSG_BUF_SIZE, HEAPID_FRONTIER_MONITOR );

	//フォントパレット
	SystemFontPaletteLoad( PALTYPE_MAIN_BG, BFM_FONT_PAL * 32, HEAPID_FRONTIER_MONITOR );
	TalkFontPaletteLoad( PALTYPE_MAIN_BG, BFM_MSGFONT_PAL * 32, HEAPID_FRONTIER_MONITOR );

	//ビットマップ追加
	FrontierMonitorAddBmpWin( wk->bgl, wk->bmpwin, GetBmpNo(wk->fr_no) );
	FMBMP_RetButtonBmpWinAdd( wk->bgl, &wk->ret_win );
	RetButtonStrPut( wk );

	ObjInit( wk );

	sys_VBlankFuncChange( VBlankFunc, (void*)wk );		//VBlankセット

	(*seq) = SEQ_GAME_INIT;

	return PROC_RES_FINISH;
}

//--------------------------------------------------------------
/**
 * @brief	プロセス関数：メイン
 *
 * @param	proc	プロセスデータ
 * @param	seq		シーケンス
 *
 * @return	"処理状況"
 */
//--------------------------------------------------------------
PROC_RESULT FrontierMonitorProc_Main( PROC * proc, int * seq )
{
	FRONTIER_MONITOR_WORK * wk  = PROC_GetWork( proc );

	switch( *seq ){

	//初期化
	case SEQ_GAME_INIT:
		if( Seq_GameInit(wk) == TRUE ){
			NextSeq( wk, seq, SEQ_GAME_START );
		}
		break;

	//ゲーム開始
	case SEQ_GAME_START:
		if( Seq_GameStart(wk) == TRUE ){
			NextSeq( wk, seq, SEQ_GAME_END );		//終了
		}
		break;

	//終了
	case SEQ_GAME_END:
		if( Seq_GameEnd(wk) == TRUE ){
			return PROC_RES_FINISH;
		}
	}

	ObjAnmMain( wk );
	CATS_Draw( wk->crp );

	return PROC_RES_CONTINUE;
}

//--------------------------------------------------------------
/**
 * @brief	プロセス関数：終了
 *
 * @param	proc	プロセスデータ
 * @param	seq		シーケンス
 *
 * @return	"処理状況"
 */
//--------------------------------------------------------------
PROC_RESULT FrontierMonitorProc_End( PROC * proc, int * seq )
{
	int i;
	FRONTIER_MONITOR_WORK* wk = PROC_GetWork( proc );

	ObjExit( wk );

	//パレットフェード開放
	PaletteFadeWorkAllocFree( wk->pfd, FADE_MAIN_OBJ );
	PaletteFadeWorkAllocFree( wk->pfd, FADE_MAIN_BG );

	//パレットフェードシステム開放
	PaletteFadeFree( wk->pfd );
	wk->pfd = NULL;

	MSGMAN_Delete( wk->msgman );						//メッセージマネージャ開放
	WORDSET_Delete( wk->wordset );
	STRBUF_Delete( wk->msg_buf );						//メッセージバッファ開放

	FMBMP_RetButtonBmpWinDel( &wk->ret_win );
	FrontierMonitorExitBmpWin( wk->bmpwin, GetBmpNo(wk->fr_no) );	//BMPウィンドウ開放

	Frontier_BgExit( wk->bgl );							//BGL削除

	FontProc_UnloadFont( FONT_TOUCH );

	PROC_FreeWork( proc );								//ワーク開放

	sys_VBlankFuncChange( NULL, NULL );					//VBlankセット
	sys_DeleteHeap( HEAPID_FRONTIER_MONITOR );

	return PROC_RES_FINISH;
}


//==============================================================================================
//
//	シーケンス
//
//==============================================================================================

//--------------------------------------------------------------
/**
 * @brief	ゲーム初期化
 *
 * @param	wk		FRONTIER_MONITOR_WORK型のポインタ
 *
 * @return	"TRUE = 次へ、FALSE = 継続"
 */
//--------------------------------------------------------------
static BOOL Seq_GameInit( FRONTIER_MONITOR_WORK* wk )
{
	switch( wk->sub_seq ){

	case 0:
		if( StageCheck( wk ) == TRUE ){
			StageInit( wk );
		}else{
			Frontier_Write( wk );
		}
		wk->sub_seq++;
		break;

	//ブラックイン
	case 1:
		WIPE_SYS_Start( WIPE_PATTERN_WMS, WIPE_TYPE_FADEIN, WIPE_TYPE_FADEIN,
						WIPE_FADE_BLACK, WIPE_DEF_DIV, WIPE_DEF_SYNC*3, HEAPID_FRONTIER_MONITOR );
		wk->sub_seq++;
		break;

	//フェード終了待ち
	case 2:
		if( WIPE_SYS_EndCheck() == TRUE ){
			return TRUE;
		}
		break;
	};

	return FALSE;
}

//--------------------------------------------------------------
/**
 * @brief	ゲーム開始
 *
 * @param	wk		FRONTIER_MONITOR_WORK型のポインタ
 *
 * @return	"TRUE = 次へ、FALSE = 継続"
 */
//--------------------------------------------------------------
static BOOL Seq_GameStart( FRONTIER_MONITOR_WORK* wk )
{
	switch( wk->sub_seq ){
	case MAINSEQ_INIT:				// 開始処理
		if( StageCheck( wk ) == TRUE ){
			wk->sub_seq = MAINSEQ_STAGE_STR_SELECT;
		}else{
			wk->sub_seq = MAINSEQ_NORMAL_MAIN;
		}
		break;

	case MAINSEQ_NORMAL_MAIN:		// 通常メイン
		if( GF_TP_SingleHitTrg( &EndHitTbl ) == TRUE ||
			( sys.trg & (PAD_BUTTON_DECIDE|PAD_BUTTON_CANCEL) ) ){
			Snd_SePlay( SEQ_SE_DP_DECIDE );
			RetButtonAnmSet( wk );
			wk->next_seq = MAINSEQ_END;
			wk->sub_seq  = MAINSEQ_BUTTON_ANM;
		}
		break;

	case MAINSEQ_STAGE_STR_INIT:	// ステージ五十音選択初期化
		StagePageChange( wk, FM_STAGE_STR_SELECT );
		wk->sub_seq = MAINSEQ_STAGE_STR_SELECT;
		break;

	case MAINSEQ_STAGE_STR_SELECT:	// ステージ五十音選択
		wk->sub_seq = StageStrSelectMain( wk );
		break;

	case MAINSEQ_STAGE_POKE_INIT:	// ステージポケモン選択初期化
		StagePageChange( wk, FM_STAGE_POKE_SELECT );
		wk->sub_seq = MAINSEQ_STAGE_POKE_SELECT;
		break;

	case MAINSEQ_STAGE_POKE_SELECT:	// ステージポケモン選択
		wk->sub_seq = StagePokeSelMain( wk );
		break;

	case MAINSEQ_STAGE_POKE_SEL_CHANGE:	// ステージポケモン選択ページ切り替え
		wk->sub_seq = StagePokeSelPageChange( wk );
		break;

	case MAINSEQ_STAGE_RESULT_INIT:	// ステージ成績画面選択初期化
		StagePageChange( wk, FM_STAGE_PAGE_RESULT );
		wk->sub_seq = MAINSEQ_STAGE_RESULT;
		break;

	case MAINSEQ_STAGE_RESULT:		// ステージ成績画面
		if( GF_TP_SingleHitTrg( &EndHitTbl ) == TRUE ||
			( sys.trg & (PAD_BUTTON_DECIDE|PAD_BUTTON_CANCEL) ) ){
			Snd_SePlay( SEQ_SE_DP_DECIDE );
			RetButtonAnmSet( wk );
			wk->next_seq = MAINSEQ_STAGE_POKE_INIT;
			wk->sub_seq  = MAINSEQ_BUTTON_ANM;
		}
		break;

	case MAINSEQ_BUTTON_ANM:		// ボタンアニメ
		if( ButtonAnmMain( wk ) == FALSE ){
			wk->sub_seq = wk->next_seq;
		}
		break;


	case MAINSEQ_END:				// 終了
		return TRUE;
	}

	return FALSE;
}

//--------------------------------------------------------------
/**
 * @brief	シーケンス：終了へ
 *
 * @param	wk		FRONTIER_MONITOR_WORK型のポインタ
 *
 * @return	"TRUE = 次へ、FALSE = 継続"
 */
//--------------------------------------------------------------
static BOOL Seq_GameEnd( FRONTIER_MONITOR_WORK* wk )
{
	int i;

	switch( wk->sub_seq ){

	//フェードアウト
	case 0:
		WIPE_SYS_Start( WIPE_PATTERN_WMS, WIPE_TYPE_FADEOUT, WIPE_TYPE_FADEOUT,
						WIPE_FADE_BLACK, WIPE_DEF_DIV, WIPE_DEF_SYNC, HEAPID_FRONTIER_MONITOR );
		wk->sub_seq++;
		break;

	//フェード終了待ち
	case 1:
		if( WIPE_SYS_EndCheck() == TRUE ){
			return TRUE;
		}
		break;
	};

	return FALSE;
}


//==============================================================================================
//
//	設定
//
//==============================================================================================

//--------------------------------------------------------------
/**
 * @brief	VBlank関数
 *
 * @param	work	ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------
static void VBlankFunc( void * work )
{
	FRONTIER_MONITOR_WORK* wk = work;

	//パレット転送
	if( wk->pfd != NULL ){
		PaletteFadeTrans( wk->pfd );
	}

	GF_BGL_VBlankFunc( wk->bgl );

	CATS_RenderOamTrans();

	OS_SetIrqCheckFlag( OS_IE_V_BLANK );
}

//--------------------------------------------------------------
/**
 * @brief	VRAM設定
 *
 * @param	none
 *
 * @return	none
 *
 * 細かく設定していないので注意！
 */
//--------------------------------------------------------------
static void SetVramBank(void)
{
	GF_BGL_DISPVRAM tbl = {
		GX_VRAM_BG_128_A,				//メイン2DエンジンのBG
		GX_VRAM_BGEXTPLTT_NONE,			//メイン2DエンジンのBG拡張パレット

		GX_VRAM_SUB_BG_128_C,			//サブ2DエンジンのBG
		GX_VRAM_SUB_BGEXTPLTT_NONE,		//サブ2DエンジンのBG拡張パレット

		GX_VRAM_OBJ_128_B,				//メイン2DエンジンのOBJ
		GX_VRAM_OBJEXTPLTT_NONE,		//メイン2DエンジンのOBJ拡張パレット

		GX_VRAM_SUB_OBJ_16_I,			//サブ2DエンジンのOBJ
		GX_VRAM_SUB_OBJEXTPLTT_NONE,	//サブ2DエンジンのOBJ拡張パレット

		GX_VRAM_TEX_NONE,				//テクスチャイメージスロット
		GX_VRAM_TEXPLTT_NONE			//テクスチャパレットスロット
	};

	GF_Disp_SetBank( &tbl );
	return;
}

//--------------------------------------------------------------
/**
 * @brief	BG設定
 *
 * @param	init	BGLデータ
 *
 * @return	none
 */
//--------------------------------------------------------------
static void SetBgHeader( GF_BGL_INI * ini )
{
	{	//BG SYSTEM
		GF_BGL_SYS_HEADER BGsys_data = {
			GX_DISPMODE_GRAPHICS, GX_BGMODE_0, GX_BGMODE_0, GX_BG0_AS_2D,
		};
		GF_BGL_InitBG( &BGsys_data );
	}

	{	//BG(フォント)
		GF_BGL_BGCNT_HEADER TextBgCntDat = {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xf800, GX_BG_CHARBASE_0x00000, GX_BG_EXTPLTT_01,
			0, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( ini, BFM_FRAME_WIN, &TextBgCntDat, GF_BGL_MODE_TEXT );
		GF_BGL_ClearCharSet( BFM_FRAME_WIN, 32, 0, HEAPID_FRONTIER_MONITOR );
		GF_BGL_ScrClear( ini, BFM_FRAME_WIN );
	}

	{	//上画面
		GF_BGL_BGCNT_HEADER TextBgCntDat = {
			0, 0, 0x2000, 0, GF_BGL_SCRSIZ_512x512, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xd800, GX_BG_CHARBASE_0x10000, GX_BG_EXTPLTT_01,
			1, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( ini, BFM_FRAME_BG, &TextBgCntDat, GF_BGL_MODE_TEXT );
	}

	//--------------------------------------------------------------------------------
	{	//下画面(文字)
		GF_BGL_BGCNT_HEADER TextBgCntDat = {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xf800, GX_BG_CHARBASE_0x00000, GX_BG_EXTPLTT_01,
			0, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( ini, BFM_FRAME_WIN_S, &TextBgCntDat, GF_BGL_MODE_TEXT );
		GF_BGL_ClearCharSet( BFM_FRAME_WIN_S, 32, 0, HEAPID_FRONTIER_MONITOR );
		GF_BGL_ScrClear( ini, BFM_FRAME_WIN_S );
	}
	{	//下画面(ボール)
		GF_BGL_BGCNT_HEADER TextBgCntDat = {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xf000, GX_BG_CHARBASE_0x10000, GX_BG_EXTPLTT_01,
			1, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( ini, BFM_FRAME_BG_S, &TextBgCntDat, GF_BGL_MODE_TEXT );
	}
}


//==============================================================================================
//
//	共通初期化、終了
//
//==============================================================================================

//--------------------------------------------------------------
/**
 * @brief	BG関連初期化
 *
 * @param	wk		FRONTIER_MONITOR_WORK型のポインタ
 *
 * @return	none
 */
//--------------------------------------------------------------
static void Frontier_BgInit( FRONTIER_MONITOR_WORK* wk )
{
	SetVramBank();
	SetBgHeader( wk->bgl );

	//パレットフェードシステムワーク作成
	wk->pfd = PaletteFadeInit( HEAPID_FRONTIER_MONITOR );

	//リクエストデータをmallocしてセット
	PaletteFadeWorkAllocSet( wk->pfd, FADE_MAIN_OBJ, FADE_PAL_ALL_SIZE, HEAPID_FRONTIER_MONITOR );
	PaletteFadeWorkAllocSet( wk->pfd, FADE_MAIN_BG, FADE_PAL_ALL_SIZE, HEAPID_FRONTIER_MONITOR );

	//上画面背景
	Frontier_SetMainBgGraphic( wk, BFM_FRAME_BG );
//	Frontier_SetMainBgPalette();

	//下画面背景、パレットセット
	Frontier_SetSubBgGraphic( wk, BFM_FRAME_BG_S );
	return;
}

//--------------------------------------------------------------
/**
 * @brief	BG解放
 *
 * @param	ini		BGLデータ
 *
 * @return	none
 */
//--------------------------------------------------------------
static void Frontier_BgExit( GF_BGL_INI * ini )
{
	//メイン画面の各面の表示コントロール(表示OFF)
	GF_Disp_GX_VisibleControl(	GX_PLANEMASK_BG0 |
								GX_PLANEMASK_BG1 |
								GX_PLANEMASK_BG2 |
								GX_PLANEMASK_BG3 |
								GX_PLANEMASK_OBJ,
								VISIBLE_OFF );

	//サブ画面の各面の表示コントロール(表示OFF)
	GF_Disp_GXS_VisibleControl(	GX_PLANEMASK_BG0 |
								GX_PLANEMASK_BG1 |
								GX_PLANEMASK_BG2 |
								GX_PLANEMASK_BG3 |
								GX_PLANEMASK_OBJ,
								VISIBLE_OFF );

	//GF_BGL_BGControlSetで取得したメモリを開放
	GF_BGL_BGControlExit( ini, BFM_FRAME_WIN );
	GF_BGL_BGControlExit( ini, BFM_FRAME_BG );
	GF_BGL_BGControlExit( ini, BFM_FRAME_WIN_S );
	GF_BGL_BGControlExit( ini, BFM_FRAME_BG_S );

	sys_FreeMemoryEz( ini );
	return;
}


//==============================================================================================
//
//	ツール
//
//==============================================================================================

//--------------------------------------------------------------
/**
 * @brief	シーケンス変更
 *
 * @param	wk		FRONTIER_MONITOR_WORK型のポインタ
 * @param	seq		シーケンスのポインタ
 * @param	next	次のシーケンス定義
 *
 * @return	none
 */
//--------------------------------------------------------------
static void NextSeq( FRONTIER_MONITOR_WORK* wk, int* seq, int next )
{
	wk->sub_seq = 0;
	*seq		= next;
	return;
}

//--------------------------------------------------------------
/**
 * @brief	キーチェック
 *
 * @param	key		チェックするキー
 *
 * @return	"結果"
 */
//--------------------------------------------------------------
static int KeyCheck( int key )
{
	return (sys.cont & key);
}

//--------------------------------------------------------------
/**
 * @brief	施設ナンバーからBMPナンバーを取得
 *
 * @param	fr_no		施設ナンバー
 *
 * @return	"BMPナンバー"
 */
//--------------------------------------------------------------
static u8 GetBmpNo( u8 fr_no )
{
	u8 bmp_no;

	bmp_no = 0;

	switch( fr_no ){

	case FRONTIER_NO_FACTORY_LV50:
	case FRONTIER_NO_FACTORY_LV100:
		bmp_no = 0;
		break;

	case FRONTIER_NO_STAGE:
		bmp_no = 1;
		break;

	case FRONTIER_NO_CASTLE:
		bmp_no = 2;
		break;

	case FRONTIER_NO_ROULETTE:
		bmp_no = 3;
		break;

	case FRONTIER_NO_TOWER:
		bmp_no = 4;
		break;
	};

	return bmp_no;
}


//==============================================================================================
//
//	BGグラフィックデータ
//
//==============================================================================================

//--------------------------------------------------------------
/**
 * @brief	グラフィックデータセット：上画面背景(シングル、ダブル)
 *
 * @param	wk		FRONTIER_MONITOR_WORK型のポインタ
 * @param	frm		フレームナンバー
 *
 * @return	none
 */
//--------------------------------------------------------------
static void Frontier_SetMainBgGraphic( FRONTIER_MONITOR_WORK * wk, u32 frm  )
{
	ARCHANDLE* hdl;
	hdl = ArchiveDataHandleOpen( ARC_FRONTIER_BG, HEAPID_FRONTIER_MONITOR );

	ArcUtil_HDL_BgCharSet(	hdl, BF_SEISEKI_NCGR_BIN,
							wk->bgl, frm, 0, 0, 1, HEAPID_FRONTIER_MONITOR );

	ArcUtil_HDL_PalSet(
		hdl, BF_SEISEKI_NCLR, PALTYPE_MAIN_BG,
		0, 0x20*3, HEAPID_FRONTIER_MONITOR );

	ArcUtil_HDL_ScrnSet(hdl, BF_SEISEKI_NSCR_BIN,
						wk->bgl, frm, 0, 0, 1, HEAPID_FRONTIER_MONITOR );

	{	// ステージ用の矢印読み込み
		NNSG2dScreenData * scrn;
		void * buf;
		buf = ArcUtil_HDL_ScrnDataGet(
				hdl, BF_STAGE_ARROW_NSCR_BIN, TRUE, &scrn, HEAPID_FRONTIER_MONITOR );
		MI_CpuCopy16( scrn->rawData, wk->starrow, sizeof(u16)*4*4*3 );
		sys_FreeMemoryEz( buf );
	}

	ArchiveDataHandleClose( hdl );
	return;
}

//--------------------------------------------------------------
/**
 * @brief	上画面背景パレット設定
 *
 * @param	none
 *
 * @return	none
 */
//--------------------------------------------------------------
/*
static void Frontier_SetMainBgPalette(void)
{
	void *buf;
	NNSG2dPaletteData *dat;

	buf = ArcUtil_PalDataGet(ARC_FRONTIER_BG, BF_SEISEKI_NCLR, &dat,HEAPID_FRONTIER_MONITOR);

	DC_FlushRange( dat->pRawData, (sizeof(u16)*16*2) );
	GX_LoadBGPltt( dat->pRawData, 0, (sizeof(u16)*16*2) );		//メイン

	sys_FreeMemoryEz(buf);
	return;
}
*/

//--------------------------------------------------------------
/**
 * @brief	グラフィックデータセット：下画面背景、パレットセット
 *
 * @param	wk		FRONTIER_MONITOR_WORK型のポインタ
 * @param	frm		フレームナンバー
 *
 * @return	none
 */
//--------------------------------------------------------------
static void Frontier_SetSubBgGraphic( FRONTIER_MONITOR_WORK * wk, u32 frm  )
{
	ARCHANDLE* hdl;

	hdl = ArchiveDataHandleOpen( ARC_FRONTIER_BG, HEAPID_FRONTIER_MONITOR );

	ArcUtil_HDL_BgCharSet(	hdl, BF_U_NCGR_BIN, wk->bgl, frm,
							0, 0, TRUE, HEAPID_FRONTIER_MONITOR );

	ArcUtil_HDL_ScrnSet(hdl, BF_U_NSCR_BIN, wk->bgl, frm,
						0, 0, TRUE, HEAPID_FRONTIER_MONITOR );

	ArcUtil_HDL_PalSet(	hdl, BF_U_NCLR, PALTYPE_SUB_BG,
						0, 0x20, HEAPID_FRONTIER_MONITOR );

	ArchiveDataHandleClose( hdl );
	return;
}


//==============================================================================================
//
//	メッセージ関連
//
//==============================================================================================

//--------------------------------------------------------------
/**
 * @brief	数値をセット
 *
 * @param	wk		FRONTIER_WORK型のポインタ
 * @param	bufID	バッファID
 * @param	number	セットする数値
 *
 * @retval	none
 *
 * 4桁固定にしている
 */
//--------------------------------------------------------------
static void SetNumber( FRONTIER_MONITOR_WORK* wk, u32 bufID, s32 number )
{
	WORDSET_RegisterNumber(
		wk->wordset, bufID, number, 4,
		NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
//		NUMBER_DISPTYPE_SPACE, NUMBER_CODETYPE_DEFAULT );
}

//--------------------------------------------------------------------------------------------
/**
 * 文字列表示（バッファ指定）
 *
 * @param	win		BMPWIN
 * @param	str		文字列バッファ
 * @param	x		表示基準Ｘ座標
 * @param	y		表示基準Ｙ座標
 * @param	fnt		フォント
 * @param	col		カラー
 * @param	mode	表示モード
 *
 * @return	none
 *
 * @li	mode = STRPRINT_MODE_LEFT	: 左詰
 * @li	mode = STRPRINT_MODE_RIGHT	: 右詰
 * @li	mode = STRPRINT_MODE_CENTER	: 中央
 */
//--------------------------------------------------------------------------------------------
static void StrPrintCore(
				GF_BGL_BMPWIN * win, STRBUF * str,
				u32 x, u32 y, FONT_TYPE fnt, GF_PRINTCOLOR col, u32 mode )
{
	if( mode == STRPRINT_MODE_RIGHT ){
		x -= FontProc_GetPrintStrWidth( fnt, str, 0 );
	}else if( mode == STRPRINT_MODE_CENTER ){
		x -= ( FontProc_GetPrintStrWidth( fnt, str, 0 ) / 2 );
	}
	GF_STR_PrintColor( win, fnt, str, x, y, MSG_NO_PUT, col, NULL );
}

//--------------------------------------------------------------------------------------------
/**
 * 文字列表示（固定文字列）
 *
 * @param	appwk	成績画面ワーク
 * @param	winID	BMPWIN ID
 * @param	msgID	文字列ＩＤ
 * @param	x		表示基準Ｘ座標
 * @param	y		表示基準Ｙ座標
 * @param	fnt		フォント
 * @param	col		カラー
 * @param	mode	表示モード
 *
 * @return	none
 *
 * @li	mode = STRPRINT_MODE_LEFT	: 左詰
 * @li	mode = STRPRINT_MODE_RIGHT	: 右詰
 * @li	mode = STRPRINT_MODE_CENTER	: 中央
 */
//--------------------------------------------------------------------------------------------
static void StrPrint(
				FRONTIER_MONITOR_WORK * wk,
				u32 winID, u32 msgID, u32 x, u32 y, FONT_TYPE fnt, GF_PRINTCOLOR col, u32 mode )
{
	STRBUF * str = MSGMAN_AllocString( wk->msgman, msgID );

	StrPrintCore( &wk->bmpwin[winID], str, x, y, fnt, col, mode );

	STRBUF_Delete( str );
}

//--------------------------------------------------------------------------------------------
/**
 * 文字列表示（可変文字列）
 *
 * @param	appwk	成績画面ワーク
 * @param	man		メッセージマネージャ
 * @param	winID	BMPWIN ID
 * @param	msgID	文字列ＩＤ
 * @param	x		表示基準Ｘ座標
 * @param	y		表示基準Ｙ座標
 * @param	fnt		フォント
 * @param	col		カラー
 * @param	mode	表示モード
 *
 * @return	none
 *
 * @li	mode = STRPRINT_MODE_LEFT	: 左詰
 * @li	mode = STRPRINT_MODE_RIGHT	: 右詰
 * @li	mode = STRPRINT_MODE_CENTER	: 中央
 */
//--------------------------------------------------------------------------------------------
static void ExStrPrint(
				FRONTIER_MONITOR_WORK * wk,
				u32 winID, u32 msgID, u32 x, u32 y, FONT_TYPE fnt, GF_PRINTCOLOR col, u32 mode )
{
	STRBUF * str = MSGMAN_AllocString( wk->msgman, msgID );

	WORDSET_ExpandStr( wk->wordset, wk->msg_buf, str );

	StrPrintCore( &wk->bmpwin[winID], wk->msg_buf, x, y, fnt, col, mode );

	STRBUF_Delete( str );
}

//--------------------------------------------------------------
/**
 * @brief	各施設ごとの情報を書き込む
 *
 * @param	wk		FRONTIER_WORK型のポインタ
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void Frontier_Write( FRONTIER_MONITOR_WORK* wk )
{
	int msg_id;

	switch( wk->fr_no ){

	//ファクトリー
	case FRONTIER_NO_FACTORY_LV50:
	case FRONTIER_NO_FACTORY_LV100:
		Factory_SetLv50Info( wk );	//「ＬＶ５０」
		Factory_SetLv100Info( wk );	//「オープン」
		break;

	//ステージ
	case FRONTIER_NO_STAGE:
		Stage_SetInfo( wk );
		break;

	case FRONTIER_NO_CASTLE:
		Castle_SetInfo( wk );
		break;

	case FRONTIER_NO_ROULETTE:
		Roulette_SetInfo( wk );
		break;

	case FRONTIER_NO_TOWER:
		if( (wk->type == BTWR_MODE_SINGLE) ||
			(wk->type == BTWR_MODE_DOUBLE) ){
			Tower_SetInfoSingleDouble( wk );
		}else{
			Tower_SetInfoMulti( wk );
		}
		break;

	//エラー回避
	default:
		Roulette_SetInfo( wk );
		break;

	};

	return;
}


//==============================================================================================
//
//	ファクトリー
//
//==============================================================================================

//--------------------------------------------------------------
/**
 * @brief	LV50情報をセット
 *
 * @param	wk		FRONTIER_WORK型のポインタ
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void Factory_SetLv50Info( FRONTIER_MONITOR_WORK* wk )
{
	int	msgID;
	int	recID;

	// 塗りつぶし
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BF_BMPWIN_TITLE], FBMP_COL_NULL );
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BF_BMPWIN_ENTRY1], FBMP_COL_NULL );
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BF_BMPWIN_BEFORE], FBMP_COL_NULL );
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BF_BMPWIN_MAX], FBMP_COL_NULL );

	//「バトルファクトリー」
	StrPrint(
		wk, BF_BMPWIN_TITLE, msg_bf_seiseki_list02,
		FACTORY_TITLE_PX, 0, FONT_SYSTEM, FCOL_N_WHITE, STRPRINT_MODE_LEFT );

	// タイプ
	if( wk->type == FACTORY_TYPE_SINGLE ){
		msgID = msg_bf_seiseki_list06;
	}else if( wk->type == FACTORY_TYPE_DOUBLE ){
		msgID = msg_bf_seiseki_list07;
	}else{
		msgID = msg_bf_seiseki_list08;
	}
	StrPrint(
		wk, BF_BMPWIN_TITLE, msgID,
		FACTORY_TYPE_PX, 0, FONT_SYSTEM, FCOL_N_WHITE, STRPRINT_MODE_LEFT );

	//「ＬＶ５０」
	StrPrint(
		wk, BF_BMPWIN_ENTRY1, msg_bf_seiseki_list13,
		FACTORY_LV50_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );

	//「レンタル／こうかん」
	StrPrint(
		wk, BF_BMPWIN_ENTRY1, msg_bf_seiseki_list15,
		FACTORY_LV50_CHG_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「ぜんかい」「げんざい」
	StrPrint(
		wk, BF_BMPWIN_BEFORE, Factory_GetMsg(wk,0),
		FACTORY_LV50_NOW_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );

	// 連勝数
	recID = FactoryScr_GetWinRecordID( FACTORY_LEVEL_50, wk->type );
	SetNumber( wk, 0, FrontierRecord_Get(wk->f_sv,recID,FRONTIER_RECORD_NOT_FRIEND) );
	ExStrPrint(
		wk, BF_BMPWIN_BEFORE, msg_bf_seiseki_list24,
		FACTORY_LV50_NOW_WIN_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「れんしょう」
	StrPrint(
		wk, BF_BMPWIN_BEFORE, msg_bf_seiseki_list25,
		FACTORY_LV50_NOW_WIN_STR_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	// レンタル・交換回数
	recID = FactoryScr_GetTradeRecordID( FACTORY_LEVEL_50, wk->type );
	SetNumber( wk, 0, FrontierRecord_Get(wk->f_sv,recID,FRONTIER_RECORD_NOT_FRIEND) );
	ExStrPrint(
		wk, BF_BMPWIN_BEFORE, msg_bf_seiseki_list26,
		FACTORY_LV50_NOW_CHG_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「かい」
	StrPrint(
		wk, BF_BMPWIN_BEFORE, msg_bf_seiseki_list27,
		FACTORY_LV50_NOW_CHG_STR_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「さいこう」
	StrPrint(
		wk, BF_BMPWIN_MAX, msg_bf_seiseki_list10,
		FACTORY_LV50_BST_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );

	// 連勝数
	recID = FactoryScr_GetMaxWinRecordID( FACTORY_LEVEL_50, wk->type );
	SetNumber( wk, 0, FrontierRecord_Get(wk->f_sv,recID,FRONTIER_RECORD_NOT_FRIEND) );
	ExStrPrint(
		wk, BF_BMPWIN_MAX, msg_bf_seiseki_list24,
		FACTORY_LV50_BST_WIN_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「れんしょう」
	StrPrint(
		wk, BF_BMPWIN_MAX, msg_bf_seiseki_list25,
		FACTORY_LV50_BST_WIN_STR_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	// レンタル・交換回数
	recID = FactoryScr_GetMaxTradeRecordID( FACTORY_LEVEL_50, wk->type );
	SetNumber( wk, 0, FrontierRecord_Get(wk->f_sv,recID,FRONTIER_RECORD_NOT_FRIEND) );
	ExStrPrint(
		wk, BF_BMPWIN_MAX, msg_bf_seiseki_list26,
		FACTORY_LV50_BST_CHG_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「かい」
	StrPrint(
		wk, BF_BMPWIN_MAX, msg_bf_seiseki_list27,
		FACTORY_LV50_BST_CHG_STR_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BF_BMPWIN_TITLE] );
	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BF_BMPWIN_ENTRY1] );
	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BF_BMPWIN_BEFORE] );
	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BF_BMPWIN_MAX] );
}

//--------------------------------------------------------------
/**
 * @brief	LV100情報をセット
 *
 * @param	wk		FRONTIER_WORK型のポインタ
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void Factory_SetLv100Info( FRONTIER_MONITOR_WORK* wk )
{
	int	recID;

	GF_BGL_BmpWinDataFill( &wk->bmpwin[BF_BMPWIN_ENTRY2], FBMP_COL_NULL );
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BF_BMPWIN_BEFORE2], FBMP_COL_NULL );
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BF_BMPWIN_MAX2], FBMP_COL_NULL );

	//「オープンレベル」
	StrPrint(
		wk, BF_BMPWIN_ENTRY2, msg_bf_seiseki_list14,
		FACTORY_LV100_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );
	//「レンタル／こうかん」
	StrPrint(
		wk, BF_BMPWIN_ENTRY2, msg_bf_seiseki_list15,
		FACTORY_LV100_CHG_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「ぜんかい」「げんざい」
	StrPrint(
		wk, BF_BMPWIN_BEFORE2, Factory_GetMsg(wk,1),
		FACTORY_LV100_NOW_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );

	// 連勝数
	recID = FactoryScr_GetWinRecordID( FACTORY_LEVEL_OPEN, wk->type );
	SetNumber( wk, 0, FrontierRecord_Get(wk->f_sv,recID,FRONTIER_RECORD_NOT_FRIEND) );
	ExStrPrint(
		wk, BF_BMPWIN_BEFORE2, msg_bf_seiseki_list24,
		FACTORY_LV100_NOW_WIN_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「れんしょう」
	StrPrint(
		wk, BF_BMPWIN_BEFORE2, msg_bf_seiseki_list25,
		FACTORY_LV100_NOW_WIN_STR_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	// レンタル・交換回数
	recID = FactoryScr_GetTradeRecordID( FACTORY_LEVEL_OPEN, wk->type );
	SetNumber( wk, 0, FrontierRecord_Get(wk->f_sv,recID,FRONTIER_RECORD_NOT_FRIEND) );
	ExStrPrint(
		wk, BF_BMPWIN_BEFORE2, msg_bf_seiseki_list26,
		FACTORY_LV100_NOW_CHG_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「かい」
	StrPrint(
		wk, BF_BMPWIN_BEFORE2, msg_bf_seiseki_list27,
		FACTORY_LV100_NOW_CHG_STR_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「さいこう」
	StrPrint(
		wk, BF_BMPWIN_MAX2, msg_bf_seiseki_list10,
		FACTORY_LV100_BST_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );

	// 連勝数
	recID = FactoryScr_GetMaxWinRecordID( FACTORY_LEVEL_OPEN, wk->type );
	SetNumber( wk, 0, FrontierRecord_Get(wk->f_sv,recID,FRONTIER_RECORD_NOT_FRIEND) );
	ExStrPrint(
		wk, BF_BMPWIN_MAX2, msg_bf_seiseki_list24,
		FACTORY_LV100_BST_WIN_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「れんしょう」
	StrPrint(
		wk, BF_BMPWIN_MAX2, msg_bf_seiseki_list25,
		FACTORY_LV100_BST_WIN_STR_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	// レンタル・交換回数
	recID = FactoryScr_GetMaxTradeRecordID( FACTORY_LEVEL_OPEN, wk->type );
	SetNumber( wk, 0, FrontierRecord_Get(wk->f_sv,recID,FRONTIER_RECORD_NOT_FRIEND) );
	ExStrPrint(
		wk, BF_BMPWIN_MAX2, msg_bf_seiseki_list26,
		FACTORY_LV100_BST_CHG_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「かい」
	StrPrint(
		wk, BF_BMPWIN_MAX2, msg_bf_seiseki_list27,
		FACTORY_LV100_BST_CHG_STR_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BF_BMPWIN_ENTRY2] );
	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BF_BMPWIN_BEFORE2] );
	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BF_BMPWIN_MAX2] );
}

//
static u32 Factory_GetMsg( FRONTIER_MONITOR_WORK* wk, u8 level )
{
	u8 clear_flag;
	u32 clear_id;

	if( level == 0 ){
		clear_id = FRID_FACTORY_MULTI_WIFI_CLEAR_BIT;
	}else{
		clear_id = FRID_FACTORY_MULTI_WIFI_CLEAR100_BIT;
	}

	//WIFIのみ特殊
	if( wk->type == FACTORY_TYPE_WIFI_MULTI ){

		clear_flag = FrontierRecord_Get(SaveData_GetFrontier(wk->sv), clear_id,
										Frontier_GetFriendIndex(clear_id) );
	}else{
		//クリアしたかフラグを取得
		clear_flag = (u8)FACTORYSCORE_GetScoreData(	SaveData_GetFactoryScore(wk->sv),
													FACTORYSCORE_ID_CLEAR_FLAG,
													(level*FACTORY_TYPE_MAX)+wk->type, NULL );
	}

	if( clear_flag == 1 ){
		//「げんざい」
		return msg_bf_seiseki_list23;
	}

	//「ぜんかい」
	return msg_bf_seiseki_list09;
}


//==============================================================================================
//
//	ステージ
//
//==============================================================================================

//--------------------------------------------------------------
/**
 * @brief	情報をセット
 *
 * @param	wk		FRONTIER_WORK型のポインタ
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void Stage_SetInfo( FRONTIER_MONITOR_WORK* wk )
{
	int	msgID;
	u16	mons;
	u16	num;

	u8 no;
	FRONTIER_EX_SAVEDATA * fes;
	LOAD_RESULT load_result;


	// 塗りつぶし
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BS_BMPWIN_TITLE], FBMP_COL_NULL );
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BS_BMPWIN_ENTRY1], FBMP_COL_NULL );
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BS_BMPWIN_BEFORE], FBMP_COL_NULL );
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BS_BMPWIN_MAX], FBMP_COL_NULL );

	//「バトルステージ」
	StrPrint(
		wk, BS_BMPWIN_TITLE, msg_bf_seiseki_list04,
		STAGE_TITLE_PX, 0, FONT_SYSTEM, FCOL_N_WHITE, STRPRINT_MODE_LEFT );

	//「シングルせいせき」
	if( wk->type == STAGE_TYPE_SINGLE ){
		msgID = msg_bf_seiseki_list06;
	}else if( wk->type == STAGE_TYPE_DOUBLE ){
		msgID = msg_bf_seiseki_list07;
	}else{
		msgID = msg_bf_seiseki_list08;
	}
	StrPrint(
		wk, BS_BMPWIN_TITLE, msgID,
		STAGE_TYPE_PX, 0, FONT_SYSTEM, FCOL_N_WHITE, STRPRINT_MODE_LEFT );

	// ポケモン名セット
	FrontierMonitor_PokeName( wk, wk->monsno );
	ExStrPrint(
		wk, BS_BMPWIN_ENTRY1, msg_bf_seiseki_list18,
		STAGE_POKE_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );

	//「ぜんかい」
	StrPrint(
		wk, BS_BMPWIN_BEFORE, msg_bf_seiseki_list09,
		STAGE_NOW_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );

	// 連勝数
	// 挑戦中のポケモンナンバーを取得
	mons = FrontierRecord_Get(
			SaveData_GetFrontier( wk->sv ),
			StageScr_GetMonsNoRecordID( wk->type ),
			Frontier_GetFriendIndex( StageScr_GetMonsNoRecordID(wk->type) ) );
	// 挑戦中以外のポケモンの現在の連勝数は0にする
	if( wk->monsno != mons ){
		num = 0;
	}else{
		num = FrontierRecord_Get(
				wk->f_sv,
				StageScr_GetWinRecordID( wk->type ),
				FRONTIER_RECORD_NOT_FRIEND );
	}
	SetNumber(	wk, 0, num );
	ExStrPrint(
		wk, BS_BMPWIN_BEFORE, msg_bf_seiseki_list24,
		STAGE_NOW_WIN_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「れんしょう」
	StrPrint(
		wk, BS_BMPWIN_BEFORE, msg_bf_seiseki_list17,
		STAGE_NOW_WIN_STR_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「さいこう」
	StrPrint(
		wk, BS_BMPWIN_MAX, msg_bf_seiseki_list10,
		STAGE_BST_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );

	// 連勝数
	fes = FrontierEx_Load( wk->sv, HEAPID_WORLD, &load_result );
	if( load_result != LOAD_RESULT_OK ){
		num = 0;	//セーブ破壊orキーと一致しない、場合は新規データと解釈し、カウンタ0とする
	}else{
		num = FrontierEx_StageRenshou_Get(
				wk->sv, fes, StageScr_GetExMaxWinRecordID(wk->type), wk->monsno );
	}
	if( fes != NULL ){
		sys_FreeMemoryEz( fes );
	}
	SetNumber(	wk, 0, num );
	ExStrPrint(
		wk, BS_BMPWIN_MAX, msg_bf_seiseki_list24,
		STAGE_BST_WIN_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「れんしょう」
	StrPrint(
		wk, BS_BMPWIN_MAX, msg_bf_seiseki_list17,
		STAGE_BST_WIN_STR_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BS_BMPWIN_TITLE] );
	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BS_BMPWIN_ENTRY1] );
	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BS_BMPWIN_BEFORE] );
	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BS_BMPWIN_MAX] );
}

static u32 Stage_GetMsg( FRONTIER_MONITOR_WORK* wk )
{
#if 0
	u8 clear_flag;

	//WIFIのみ特殊
	if( wk->type == STAGE_TYPE_WIFI_MULTI ){
		clear_flag = FrontierRecord_Get(SaveData_GetFrontier(wk->sv),
										FRID_STAGE_MULTI_WIFI_CLEAR_BIT,
										Frontier_GetFriendIndex(FRID_STAGE_MULTI_WIFI_CLEAR_BIT) );
	}else{
		//クリアしたかフラグを取得
		clear_flag = (u8)STAGESCORE_GetScoreData(	SaveData_GetStageScore(wk->sv),
													STAGESCORE_ID_CLEAR_FLAG,
													wk->type, 0, NULL );
	}

	if( clear_flag == 1 ){
		//「げんざい」
		return msg_bf_seiseki_list23;
	}
#endif

	//「ぜんかい」
	return msg_bf_seiseki_list09;
}

//--------------------------------------------------------------------------------------------
/**
 * モンスターナンバーからポケモン名を指定バッファに登録
 *
 * @param	core		仮想マシン制御構造体へのポインタ
 *
 * @return	"0"
 */
//--------------------------------------------------------------------------------------------
static void FrontierMonitor_PokeName( FRONTIER_MONITOR_WORK* wk, u16 mons )
{
	MSGDATA_MANAGER* man;
	STRBUF* buf;

	man = MSGMAN_Create(MSGMAN_TYPE_DIRECT,ARC_MSG,NARC_msg_monsname_dat,HEAPID_FRONTIER_MONITOR);
	buf = MSGMAN_AllocString( man, mons );
	MSGMAN_Delete( man );

	//単語セット
	//バッファID
	//文字列
	//性別コード
	//単／複（TRUEで単数）
	//言語コード
	WORDSET_RegisterWord( wk->wordset, 0, buf, 0, 0, PM_LANG );
	STRBUF_Delete( buf );
	return;
}


//==============================================================================================
//
//	キャッスル
//
//==============================================================================================

//--------------------------------------------------------------
/**
 * @brief	情報をセット
 *
 * @param	wk		FRONTIER_WORK型のポインタ
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void Castle_SetInfo( FRONTIER_MONITOR_WORK* wk )
{
	int msgID;
	int recID;
	int	nowCP;

	//塗りつぶし
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BC_BMPWIN_TITLE], FBMP_COL_NULL );
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BC_BMPWIN_ENTRY1], FBMP_COL_NULL );
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BC_BMPWIN_BEFORE], FBMP_COL_NULL );
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BC_BMPWIN_MAX], FBMP_COL_NULL );

	//「バトルキャッスル」
	StrPrint(
		wk, BC_BMPWIN_TITLE, msg_bf_seiseki_list03,
		CASTLE_TITLE_PX, 0, FONT_SYSTEM, FCOL_N_WHITE, STRPRINT_MODE_LEFT );

	// タイプ
	if( wk->type == CASTLE_TYPE_SINGLE ){
		msgID = msg_bf_seiseki_list06;
	}else if( wk->type == CASTLE_TYPE_DOUBLE ){
		msgID = msg_bf_seiseki_list07;
	}else{
		msgID = msg_bf_seiseki_list08;
	}
	StrPrint(
		wk, BC_BMPWIN_TITLE, msgID,
		CASTLE_TYPE_PX, 0, FONT_SYSTEM, FCOL_N_WHITE, STRPRINT_MODE_LEFT );

	//「キャッスルポイント」
	StrPrint(
		wk, BC_BMPWIN_ENTRY1, msg_bf_seiseki_list16,
		CASTLE_POINT_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「ぜんかい」「げんざい」
	StrPrint(
		wk, BC_BMPWIN_BEFORE, Castle_GetMsg(wk),
		CASTLE_NOW_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );

	// 部屋数
	recID = CastleScr_GetWinRecordID( wk->type );
	SetNumber( wk, 0, FrontierRecord_Get(wk->f_sv,recID,FRONTIER_RECORD_NOT_FRIEND) );
	ExStrPrint(
		wk, BC_BMPWIN_BEFORE, msg_bf_seiseki_list24,
		CASTLE_NOW_ROOM_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「へや　クリア」
	StrPrint(
		wk, BC_BMPWIN_BEFORE, msg_bf_seiseki_list28,
		CASTLE_NOW_ROOM_STR_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	// ポイント数
	nowCP = FrontierRecord_Get(
				SaveData_GetFrontier( wk->sv ),
				CastleScr_GetCPRecordID( wk->type ),
				Frontier_GetFriendIndex( CastleScr_GetCPRecordID(wk->type) ) );
	SetNumber(	wk, 0, nowCP );
	ExStrPrint(
		wk, BC_BMPWIN_BEFORE, msg_bf_seiseki_list29,
		CASTLE_NOW_POINT_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「ＣＰ」
	StrPrint(
		wk, BC_BMPWIN_BEFORE, msg_bf_seiseki_list30,
		CASTLE_NOW_POINT_STR_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「さいこう」
	StrPrint(
		wk, BC_BMPWIN_MAX, msg_bf_seiseki_list10,
		CASTLE_BST_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );

	// 部屋数
	recID = CastleScr_GetMaxWinRecordID( wk->type );
	SetNumber( wk, 0, FrontierRecord_Get(wk->f_sv,recID,FRONTIER_RECORD_NOT_FRIEND) );
	ExStrPrint(
		wk, BC_BMPWIN_MAX, msg_bf_seiseki_list24,
		CASTLE_BST_ROOM_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「へや　クリア」
	StrPrint(
		wk, BC_BMPWIN_MAX, msg_bf_seiseki_list28,
		CASTLE_BST_ROOM_STR_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	// ポイント数
	nowCP = FrontierRecord_Get(
				SaveData_GetFrontier( wk->sv ),
				CastleScr_GetRemainderCPRecordID( wk->type ),
				Frontier_GetFriendIndex( CastleScr_GetRemainderCPRecordID(wk->type) ) );
	SetNumber(	wk, 0, nowCP );
	ExStrPrint(
		wk, BC_BMPWIN_MAX, msg_bf_seiseki_list29,
		CASTLE_BST_POINT_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「ＣＰ」
	StrPrint(
		wk, BC_BMPWIN_MAX, msg_bf_seiseki_list30,
		CASTLE_BST_POINT_STR_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BC_BMPWIN_TITLE] );
	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BC_BMPWIN_ENTRY1] );
	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BC_BMPWIN_BEFORE] );
	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BC_BMPWIN_MAX] );
}

static u32 Castle_GetMsg( FRONTIER_MONITOR_WORK* wk )
{
	u8 clear_flag;

	//WIFIのみ特殊
	if( wk->type == CASTLE_TYPE_WIFI_MULTI ){
		clear_flag = FrontierRecord_Get(SaveData_GetFrontier(wk->sv),
										FRID_CASTLE_MULTI_WIFI_CLEAR_BIT,
										Frontier_GetFriendIndex(FRID_CASTLE_MULTI_WIFI_CLEAR_BIT) );
	}else{
		//クリアしたかフラグを取得
		clear_flag = (u8)CASTLESCORE_GetScoreData(	SaveData_GetCastleScore(wk->sv),
													CASTLESCORE_ID_CLEAR_FLAG,
													wk->type, 0, NULL );
	}

	if( clear_flag == 1 ){
		//「げんざい」
		return msg_bf_seiseki_list23;
	}

	//「ぜんかい」
	return msg_bf_seiseki_list09;
}


//==============================================================================================
//
//	ルーレット
//
//==============================================================================================

//--------------------------------------------------------------
/**
 * @brief	情報をセット
 *
 * @param	wk		FRONTIER_WORK型のポインタ
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void Roulette_SetInfo( FRONTIER_MONITOR_WORK* wk )
{
	int msgID;
	int recID;

	// 塗りつぶし
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BR_BMPWIN_TITLE], FBMP_COL_NULL );
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BR_BMPWIN_BEFORE], FBMP_COL_NULL );
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BR_BMPWIN_MAX], FBMP_COL_NULL );

	//「バトルルーレット」
	StrPrint(
		wk, BR_BMPWIN_TITLE, msg_bf_seiseki_list05,
		ROULETTE_TITLE_PX, 0, FONT_SYSTEM, FCOL_N_WHITE, STRPRINT_MODE_LEFT );

	//「シングルせいせき」
	if( wk->type == ROULETTE_TYPE_SINGLE ){
		msgID = msg_bf_seiseki_list06;
	}else if( wk->type == ROULETTE_TYPE_DOUBLE ){
		msgID = msg_bf_seiseki_list07;
	}else{
		msgID = msg_bf_seiseki_list08;
	}
	StrPrint(
		wk, BR_BMPWIN_TITLE, msgID,
		ROULETTE_TYPE_PX, 0, FONT_SYSTEM, FCOL_N_WHITE, STRPRINT_MODE_LEFT );

	//「ぜんかい」「げんざい」
	StrPrint(
		wk, BR_BMPWIN_BEFORE, Roulette_GetMsg(wk),
		ROULETTE_NOW_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );

	// クリア数
	recID = RouletteScr_GetWinRecordID( wk->type );
	SetNumber( wk, 0, FrontierRecord_Get(wk->f_sv,recID,FRONTIER_RECORD_NOT_FRIEND) );
	ExStrPrint(
		wk, BR_BMPWIN_BEFORE, msg_bf_seiseki_list24,
		ROULETTE_NOW_WIN_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「ゲーム　クリア」
	StrPrint(
		wk, BR_BMPWIN_BEFORE, msg_bf_seiseki_list31,
		ROULETTE_NOW_WIN_STR_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「さいこう」
	StrPrint(
		wk, BR_BMPWIN_MAX, msg_bf_seiseki_list10,
		ROULETTE_BST_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );

	// クリア数
	recID = RouletteScr_GetMaxWinRecordID( wk->type );
	SetNumber( wk, 0, FrontierRecord_Get(wk->f_sv,recID,FRONTIER_RECORD_NOT_FRIEND) );
	ExStrPrint(
		wk, BR_BMPWIN_MAX, msg_bf_seiseki_list24,
		ROULETTE_BST_WIN_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「ゲーム　クリア」
	StrPrint(
		wk, BR_BMPWIN_MAX, msg_bf_seiseki_list31,
		ROULETTE_BST_WIN_STR_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BR_BMPWIN_TITLE] );
	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BR_BMPWIN_BEFORE] );
	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BR_BMPWIN_MAX] );
}

static u32 Roulette_GetMsg( FRONTIER_MONITOR_WORK* wk )
{
	u8 clear_flag;

	//WIFIのみ特殊
	if( wk->type == ROULETTE_TYPE_WIFI_MULTI ){
		clear_flag = FrontierRecord_Get(SaveData_GetFrontier(wk->sv),
									FRID_ROULETTE_MULTI_WIFI_CLEAR_BIT,
									Frontier_GetFriendIndex(FRID_ROULETTE_MULTI_WIFI_CLEAR_BIT) );
	}else{
		//クリアしたかフラグを取得
		clear_flag = (u8)ROULETTESCORE_GetScoreData(SaveData_GetRouletteScore(wk->sv),
													ROULETTESCORE_ID_CLEAR_FLAG,
													wk->type, 0, NULL );
	}

	if( clear_flag == 1 ){
		//「げんざい」
		return msg_bf_seiseki_list23;
	}

	//「ぜんかい」
	return msg_bf_seiseki_list09;
}


//==============================================================================================
//
//	タワー
//
//==============================================================================================

//--------------------------------------------------------------
/**
 * @brief	シングル、ダブル情報をセット
 *
 * @param	wk		FRONTIER_WORK型のポインタ
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void Tower_SetInfoSingleDouble( FRONTIER_MONITOR_WORK* wk )
{
	int msgID;
	int recID;

	// 塗りつぶし
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BT_BMPWIN_TITLE], FBMP_COL_NULL );
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BT_BMPWIN_BEFORE0], FBMP_COL_NULL );
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BT_BMPWIN_MAX0], FBMP_COL_NULL );

	//「バトルタワー」
	StrPrint(
		wk, BT_BMPWIN_TITLE, msg_bf_seiseki_list01,
		TOWER_TITLE_PX, 0, FONT_SYSTEM, FCOL_N_WHITE, STRPRINT_MODE_LEFT );

	//「シングルせいせき」
	if( wk->type == BTWR_MODE_SINGLE ){
		msgID = msg_bf_seiseki_list06;
	}else{
		msgID = msg_bf_seiseki_list07;
	}
	StrPrint(
		wk, BT_BMPWIN_TITLE, msgID,
		TOWER_TYPE_PX, 0, FONT_SYSTEM, FCOL_N_WHITE, STRPRINT_MODE_LEFT );

	//「ぜんかい」
	StrPrint(
		wk, BT_BMPWIN_BEFORE0, Tower_GetMsg(wk,wk->type),
		TOWER_S_NOW_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );

	// 連勝数
	recID = TowerScr_GetWinRecordID( wk->type );
	SetNumber( wk, 0, FrontierRecord_Get(wk->f_sv,recID,FRONTIER_RECORD_NOT_FRIEND) );
	ExStrPrint(
		wk, BT_BMPWIN_BEFORE0, msg_bf_seiseki_list24,
		TOWER_S_NOW_WIN_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「れんしょう」
	StrPrint(
		wk, BT_BMPWIN_BEFORE0, msg_bf_seiseki_list25,
		TOWER_S_NOW_WIN_STR_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「さいこう」
	StrPrint(
		wk, BT_BMPWIN_MAX0, msg_bf_seiseki_list10,
		TOWER_S_BST_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );

	// 連勝数
	recID = TowerScr_GetMaxWinRecordID( wk->type );
	SetNumber( wk, 0, FrontierRecord_Get(wk->f_sv,recID,FRONTIER_RECORD_NOT_FRIEND) );
	ExStrPrint(
		wk, BT_BMPWIN_MAX0, msg_bf_seiseki_list24,
		TOWER_S_BST_WIN_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「れんしょう」
	StrPrint(
		wk, BT_BMPWIN_MAX0, msg_bf_seiseki_list25,
		TOWER_S_BST_WIN_STR_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BT_BMPWIN_TITLE] );
	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BT_BMPWIN_BEFORE0] );
	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BT_BMPWIN_MAX0] );
}

//--------------------------------------------------------------
/**
 * @brief	マルチ情報をセット
 *
 * @param	wk		FRONTIER_WORK型のポインタ
 *
 * @retval	none
 */
//--------------------------------------------------------------
static void Tower_SetInfoMulti( FRONTIER_MONITOR_WORK* wk )
{
	int	recID;

	// 塗りつぶし
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BT_BMPWIN_TITLE], FBMP_COL_NULL );
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BT_BMPWIN_ENTRY1], FBMP_COL_NULL );
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BT_BMPWIN_BEFORE], FBMP_COL_NULL );
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BT_BMPWIN_MAX], FBMP_COL_NULL );
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BT_BMPWIN_ENTRY2], FBMP_COL_NULL );
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BT_BMPWIN_BEFORE2], FBMP_COL_NULL );
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BT_BMPWIN_MAX2], FBMP_COL_NULL );

	//「バトルタワー」
	StrPrint(
		wk, BT_BMPWIN_TITLE, msg_bf_seiseki_list01,
		TOWER_TITLE_PX, 0, FONT_SYSTEM, FCOL_N_WHITE, STRPRINT_MODE_LEFT );

	//「マルチせいせき」
	StrPrint(
		wk, BT_BMPWIN_TITLE, msg_bf_seiseki_list08,
		TOWER_TYPE_PX, 0, FONT_SYSTEM, FCOL_N_WHITE, STRPRINT_MODE_LEFT );

	//「トレーナーとマルチ」
	StrPrint(
		wk, BT_BMPWIN_ENTRY1, msg_bf_seiseki_list11,
		TOWER_M_TR_TITLE_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );

	//「ぜんかい」
	StrPrint(
		wk, BT_BMPWIN_BEFORE, Tower_GetMsg(wk,wk->type),
		TOWER_M_TR_NOW_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );

	// 連勝数
	recID = TowerScr_GetWinRecordID( wk->type );
	SetNumber( wk, 0, FrontierRecord_Get(wk->f_sv,recID,FRONTIER_RECORD_NOT_FRIEND) );
	ExStrPrint(
		wk, BT_BMPWIN_BEFORE, msg_bf_seiseki_list24,
		TOWER_M_TR_NOW_WIN_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「れんしょう」
	StrPrint(
		wk, BT_BMPWIN_BEFORE, msg_bf_seiseki_list25,
		TOWER_M_TR_NOW_WIN_STR_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「さいこう」
	StrPrint(
		wk, BT_BMPWIN_MAX, msg_bf_seiseki_list10,
		TOWER_M_TR_BST_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );

	// 連勝数
	recID = TowerScr_GetMaxWinRecordID( wk->type );
	SetNumber( wk, 0, FrontierRecord_Get(wk->f_sv,recID,FRONTIER_RECORD_NOT_FRIEND) );
	ExStrPrint(
		wk, BT_BMPWIN_MAX, msg_bf_seiseki_list24,
		TOWER_M_TR_BST_WIN_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「れんしょう」
	StrPrint(
		wk, BT_BMPWIN_MAX, msg_bf_seiseki_list25,
		TOWER_M_TR_BST_WIN_STR_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「ともだちとマルチ」
	StrPrint(
		wk, BT_BMPWIN_ENTRY2, msg_bf_seiseki_list12,
		TOWER_M_FR_TITLE_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );

	//「ぜんかい」
	StrPrint(
		wk, BT_BMPWIN_BEFORE2, Tower_GetMsg(wk,BTWR_MODE_COMM_MULTI),
		TOWER_M_FR_NOW_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );

	// 連勝数
	recID = TowerScr_GetWinRecordID( BTWR_MODE_COMM_MULTI );
	SetNumber( wk, 0, FrontierRecord_Get(wk->f_sv,recID,FRONTIER_RECORD_NOT_FRIEND) );
	ExStrPrint(
		wk, BT_BMPWIN_BEFORE2, msg_bf_seiseki_list24,
		TOWER_M_FR_NOW_WIN_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「れんしょう」
	StrPrint(
		wk, BT_BMPWIN_BEFORE2, msg_bf_seiseki_list25,
		TOWER_M_FR_NOW_WIN_STR_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「さいこう」
	StrPrint(
		wk, BT_BMPWIN_MAX2, msg_bf_seiseki_list10,
		TOWER_M_FR_BST_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );

	// 連勝数
	recID = TowerScr_GetMaxWinRecordID( BTWR_MODE_COMM_MULTI );
	SetNumber( wk, 0, FrontierRecord_Get(wk->f_sv,recID,FRONTIER_RECORD_NOT_FRIEND) );
	ExStrPrint(
		wk, BT_BMPWIN_MAX2, msg_bf_seiseki_list24,
		TOWER_M_FR_BST_WIN_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「れんしょう」
	StrPrint(
		wk, BT_BMPWIN_MAX2, msg_bf_seiseki_list25,
		TOWER_M_FR_BST_WIN_STR_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BT_BMPWIN_TITLE] );
	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BT_BMPWIN_ENTRY1] );
	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BT_BMPWIN_BEFORE] );
	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BT_BMPWIN_MAX] );
	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BT_BMPWIN_ENTRY2] );
	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BT_BMPWIN_BEFORE2] );
	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BT_BMPWIN_MAX2] );
}

static u32 Tower_GetMsg( FRONTIER_MONITOR_WORK* wk, u8 type )
{
	u16 id;
	int flag;
	BTLTOWER_SCOREWORK* scoreSave;

	scoreSave = SaveData_GetTowerScoreData( wk->sv );

	//モードによって必要なIDを取得
	switch( type ){
	case BTWR_MODE_SINGLE:
		id = BTWR_SFLAG_SINGLE_RECORD;
		break;

	case BTWR_MODE_DOUBLE:
		id = BTWR_SFLAG_DOUBLE_RECORD;
		break;

	case BTWR_MODE_MULTI:
		id = BTWR_SFLAG_MULTI_RECORD;
		break;

	case BTWR_MODE_COMM_MULTI:
		id = BTWR_SFLAG_CMULTI_RECORD;
		break;

	case BTWR_MODE_WIFI:
		id = BTWR_SFLAG_WIFI_RECORD;
		break;

	//case BTWR_MODE_RETRY:
	//	break;

	case BTWR_MODE_WIFI_MULTI:		//07.08.06 プラチナ追加(COMM_MULTIのWIFI版 友達手帳)
		id = BTWR_SFLAG_WIFI_MULTI_RECORD;		//プラチナ追加
		break;

	//エラー回避
	default:
		id = BTWR_SFLAG_SINGLE_RECORD;
		break;
	};

	flag = TowerScoreData_SetFlags( scoreSave, id, BTWR_DATA_get );
	OS_Printf( "タワーのクリア状態 = %d\n", flag );

	if( flag == 1 ){
		//「げんざい」
		return msg_bf_seiseki_list23;
	}

	//「ぜんかい」
	return msg_bf_seiseki_list09;
}

//--------------------------------------------------------------------------------------------
/**
 * 「もどる」表示
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void RetButtonStrPut( FRONTIER_MONITOR_WORK * wk )
{
	STRBUF * str = MSGMAN_AllocString( wk->msgman, msg_bf_seiseki_list32 );

	GF_BGL_BmpWinDataFill( &wk->ret_win, 0 );

	StrPrintCore(
		&wk->ret_win, str,
		GF_BGL_BmpWinGet_SizeX(&wk->ret_win)*8/2, 0,
		FONT_TOUCH, FCOL_TOUCH, STRPRINT_MODE_CENTER );

	GF_BGL_BmpWinOnVReq( &wk->ret_win );

	STRBUF_Delete( str );
}


//============================================================================================
//	OBJ
//============================================================================================

//--------------------------------------------------------------------------------------------
/**
 * セルアクター初期化
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ObjInit( FRONTIER_MONITOR_WORK * wk )
{
	GF_Disp_GX_VisibleControl( GX_PLANEMASK_OBJ, VISIBLE_ON );		// MAIN DISP OBJ ON
	GF_Disp_GXS_VisibleControl( GX_PLANEMASK_OBJ, VISIBLE_ON );		// SUB DISP OBJ ON

	wk->csp = CATS_AllocMemory( HEAPID_FRONTIER_MONITOR );
	wk->crp = CATS_ResourceCreate( wk->csp );

	{
		TCATS_OAM_INIT	coi = {
			0, 128,
			0, 32,
			0, 128,
			0, 32,
		};
		TCATS_CHAR_MANAGER_MAKE ccmm = {
//			ZKN2_OBJ_MAX,
			1024,
			1024*128,
			1024*16,
			GX_OBJVRAMMODE_CHAR_1D_32K,
			GX_OBJVRAMMODE_CHAR_1D_32K
		};
		CATS_SystemInit( wk->csp, &coi, &ccmm, 32 );
	}
	{
		TCATS_RESOURCE_NUM_LIST	crnl = {
			CHR_ID_MAX, PAL_ID_MAX, CEL_ID_MAX, ANM_ID_MAX, 0, 0
		};
		CATS_ClactSetInit( wk->csp, wk->crp, FM_OBJ_MAX );
		CATS_ResourceManagerInit( wk->csp, wk->crp, &crnl );
	}
	{
		CLACT_U_EASYRENDER_DATA * renddata = CATS_EasyRenderGet( wk->csp );
		CLACT_U_SetSubSurfaceMatrix( renddata, 0, FM_SUB_ACTOR_DISTANCE );
	}

	{
		ARCHANDLE * ah = ArchiveDataHandleOpen( ARC_FRONTIER_OBJ, HEAPID_FRONTIER_MONITOR );

		CATS_LoadResourceCharArcH(
			wk->csp, wk->crp, ah,
			BF_OBJ_NCGR_BIN, 1, NNS_G2D_VRAM_TYPE_2DMAIN, CHR_ID_RET_BUTTON );

		CATS_LoadResourcePlttArcH(
			wk->csp, wk->crp, ah,
			BF_OBJ_NCLR, 0, PALSIZ_RET_BUTTON, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_RET_BUTTON );

		CATS_LoadResourceCellArcH(
			wk->csp, wk->crp, ah,
			BF_OBJ_NCER_BIN, 1, CEL_ID_RET_BUTTON );

		CATS_LoadResourceCellAnmArcH(
			wk->csp, wk->crp, ah,
			BF_OBJ_NANR_BIN, 1, ANM_ID_RET_BUTTON );

		ArchiveDataHandleClose( ah );
	}

	{
		u32	i;

		for( i=0; i<FM_OBJ_MAX; i++ ){
			wk->cap[i] = CATS_ObjectAdd_S( wk->csp, wk->crp, &ClaAddPrm[i] );
		}
	}
}

//--------------------------------------------------------------------------------------------
/**
 * セルアクター解放
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ObjExit( FRONTIER_MONITOR_WORK * wk )
{
	u32	i;

	for( i=0; i<FM_OBJ_MAX; i++ ){
		if( wk->cap[i] == NULL ){ continue; }
		CATS_ActorPointerDelete_S( wk->cap[i] );
		wk->cap[i] = NULL;
	}

	CATS_ResourceDestructor_S( wk->csp, wk->crp );
	CATS_FreeMemory( wk->csp );
}

//--------------------------------------------------------------------------------------------
/**
 * セルアクターアニメメイン
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ObjAnmMain( FRONTIER_MONITOR_WORK * wk )
{
	u32	i;

	for( i=0; i<FM_OBJ_MAX; i++ ){
		if( wk->cap[i] != NULL ){
			CATS_ObjectUpdateCap( wk->cap[i] );
		}
	}
}

//--------------------------------------------------------------------------------------------
/**
 * セルアクターアニメ変更
 *
 * @param	wk		成績画面ワーク
 * @param	id		OBJ ID
 * @param	anm		アニメ番号
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ObjAnmSet( FRONTIER_MONITOR_WORK * wk, u32 id, u32 anm )
{
	CATS_ObjectAnimeFrameSetCap( wk->cap[id], 0 );
	CATS_ObjectAnimeSeqSetCap( wk->cap[id], anm );
}

//--------------------------------------------------------------------------------------------
/**
 * セルアクター表示座標セット
 *
 * @param	wk		成績画面ワーク
 * @param	id		OBJ ID
 * @param	px		X座標
 * @param	py		Y座標
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ObjPosSet( FRONTIER_MONITOR_WORK * wk, u32 id, s16 px, s16 py )
{
	CATS_ObjectPosSetCap( wk->cap[id], px, py );
}


//--------------------------------------------------------------------------------------------
/**
 * ボタンアニメ処理
 *
 * @param	wk		成績画面ワーク
 *
 * @retval	"TRUE = アニメ中"
 * @retval	"FALSE = それ以外"
 */
//--------------------------------------------------------------------------------------------
static BOOL ButtonAnmMain( FRONTIER_MONITOR_WORK * wk )
{
	switch( wk->btn_seq ){
	case 0:
		if( wk->btn_mode == BTN_ANM_MODE_OBJ ){
			CATS_ObjectPaletteSetCap( wk->cap[wk->btn_id], wk->btn_pal1 );
		}else{
			GF_BGL_ScrPalChange(
				wk->bgl, wk->btn_id,
				wk->btn_px, wk->btn_py, wk->btn_sx, wk->btn_sy, wk->btn_pal1 );
			GF_BGL_LoadScreenV_Req( wk->bgl, wk->btn_id );
		}
		wk->btn_seq++;
		break;

	case 1:
		wk->btn_cnt++;
		if( wk->btn_cnt != 4 ){ break; }
		if( wk->btn_mode == BTN_ANM_MODE_OBJ ){
			CATS_ObjectPaletteSetCap( wk->cap[wk->btn_id], wk->btn_pal2 );
		}else{
			GF_BGL_ScrPalChange(
				wk->bgl, wk->btn_id,
				wk->btn_px, wk->btn_py, wk->btn_sx, wk->btn_sy, wk->btn_pal2 );
			GF_BGL_LoadScreenV_Req( wk->bgl, wk->btn_id );
		}
		wk->btn_cnt = 0;
		wk->btn_seq++;
		break;

	case 2:
		wk->btn_cnt++;
		if( wk->btn_cnt == 2 ){
			return FALSE;
		}
	}

	return TRUE;
}

//--------------------------------------------------------------------------------------------
/**
 * 「もどる」ボタンアニメ設定
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void RetButtonAnmSet( FRONTIER_MONITOR_WORK * wk )
{
	wk->btn_mode = BTN_ANM_MODE_OBJ;
	wk->btn_id   = FM_OBJ_RET_BUTTON;
	wk->btn_pal1 = 1;
	wk->btn_pal2 = 0;

	wk->btn_seq = 0;
	wk->btn_cnt = 0;
}


//============================================================================================
//	ステージ用処理
//============================================================================================

//--------------------------------------------------------------------------------------------
/**
 * ステージチェック
 *
 * @param	wk		成績画面ワーク
 *
 * @retval	"TRUE = ステージ"
 * @retval	"FALSE = それ以外"
 */
//--------------------------------------------------------------------------------------------
static BOOL StageCheck( FRONTIER_MONITOR_WORK * wk )
{
	if( wk->fr_no != FRONTIER_NO_STAGE ){
		return FALSE;
	}
	return TRUE;
}

//--------------------------------------------------------------------------------------------
/**
 * ステージ初期化
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StageInit( FRONTIER_MONITOR_WORK * wk )
{
	StageMsgWinLoad( wk );
	StagePokeListMake( wk );
	StageInputStrWrite( wk );
	StagePageChange( wk, FM_STAGE_STR_SELECT );
	wk->diwk = MSG_DsIconFlashAdd( NULL, MSG_DSI_SUBDISP, BFM_MSGFONT_PAL_S, HEAPID_FRONTIER_MONITOR );
}

//--------------------------------------------------------------------------------------------
/**
 * ステージ関連解放
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StageExit( FRONTIER_MONITOR_WORK * wk )
{
	MSG_DsIconFlashDelete( wk->diwk );
	StagePokeListFree( wk );
	CursorMoveWorkExit( wk );
}

//--------------------------------------------------------------------------------------------
/**
 * ステージページ切り替え
 *
 * @param	wk		成績画面ワーク
 * @param	page	ページ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StagePageChange( FRONTIER_MONITOR_WORK * wk, u32 page )
{
	switch( page ){
	case FM_STAGE_PAGE_RESULT:		// 成績画面
		GF_BGL_ScrollReq( wk->bgl, BFM_FRAME_BG, GF_BGL_SCROLL_X_SET, 0 );
		GF_BGL_ScrollReq( wk->bgl, BFM_FRAME_BG, GF_BGL_SCROLL_Y_SET, 0 );
//		GF_BGL_BmpWinOffVReq( &wk->bmpwin[BS_BMPWIN_SEARCH_AREA] );
		StagePokeNameOff( wk );
		CursorMoveWorkExit( wk );
		StageResultCursorInit( wk );
		StageResultBmpPut( wk );
		StageMsgOff( wk );
		break;

	case FM_STAGE_STR_SELECT:		// 五十音選択
		GF_BGL_ScrollReq( wk->bgl, BFM_FRAME_BG, GF_BGL_SCROLL_X_SET, 0 );
		GF_BGL_ScrollReq( wk->bgl, BFM_FRAME_BG, GF_BGL_SCROLL_Y_SET, 256 );
		StagePokeNameOff( wk );
		GF_BGL_BmpWinOnVReq( &wk->bmpwin[BS_BMPWIN_SEARCH_AREA] );
		CursorMoveWorkExit( wk );
		StageInputStrCursorMoveInit( wk );
		StageStrInputButtonInit( wk );
		StageMsgPut( wk );
		break;

	case FM_STAGE_POKE_SELECT:		// ポケモン選択
		GF_BGL_ScrollReq( wk->bgl, BFM_FRAME_BG, GF_BGL_SCROLL_X_SET, 256 );
		GF_BGL_ScrollReq( wk->bgl, BFM_FRAME_BG, GF_BGL_SCROLL_Y_SET, 256 );
		GF_BGL_BmpWinOffVReq( &wk->bmpwin[BS_BMPWIN_SEARCH_AREA] );
		StageResultBmpOff( wk );
		StagePokeNamePut( wk );
		StagePokePagePut( wk );
		StageArrowChange( wk );
		StagePokeInitialPut( wk );
		CursorMoveWorkExit( wk );
		StagePokeSelCursorMoveInit( wk );
		StageMsgPut( wk );
		break;
	}

	GF_BGL_LoadScreenV_Req( wk->bgl, BFM_FRAME_BG );
}

//--------------------------------------------------------------------------------------------
/**
 * ステージページ切り替え矢印表示
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StageArrowChange( FRONTIER_MONITOR_WORK * wk )
{
	if( wk->stscr_max == 0 ){
		GF_BGL_ScrWrite( wk->bgl, BFM_FRAME_BG, &wk->starrow[4*4*2], 34, 52, 4, 4 );
		GF_BGL_ScrWrite( wk->bgl, BFM_FRAME_BG, &wk->starrow[4*4*2], 38, 52, 4, 4 );
	}else{
		GF_BGL_ScrWrite( wk->bgl, BFM_FRAME_BG, &wk->starrow[4*4*0], 34, 52, 4, 4 );
		GF_BGL_ScrWrite( wk->bgl, BFM_FRAME_BG, &wk->starrow[4*4*1], 38, 52, 4, 4 );
	}
	GF_BGL_LoadScreenV_Req( wk->bgl, BFM_FRAME_BG );
}

//--------------------------------------------------------------------------------------------
/**
 * カーソル移動ワーク解放
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void CursorMoveWorkExit( FRONTIER_MONITOR_WORK * wk )
{
	if( wk->cmwk != NULL ){
		CURSORMOVE_Exit( wk->cmwk );
		wk->cmwk = NULL;
	}
}

//--------------------------------------------------------------------------------------------
/**
 * カーソル移動ダミーコールバック関数
 *
 * @param	work		成績画面ワーク
 * @param	now_pos		現在のカーソル位置
 * @param	old_pos		前回のカーソル位置
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void CursorMoveCallBack_Dummy( void * work, int now_pos, int old_pos )
{
}

//--------------------------------------------------------------------------------------------
/**
 * ソートデータロード
 *
 * @param	idx		インデックス
 * @param	max		データ数
 *
 * @return	ソートデータ
 */
//--------------------------------------------------------------------------------------------
static u16 * SortDataLoad( u32 idx, u32 * max )
{
	u16 * buf;
	u32	siz;

	// 読み込み
	buf = ArcUtil_LoadEx(
			ZKN_GIRA_GetZukanDataArcIdx(),
			NARC_zukan_data_zkn_sort_only_a_dat + idx,
			FALSE,
			HEAPID_FRONTIER_MONITOR,
			ALLOC_BOTTOM,
			&siz );

	*max = siz / sizeof(u16);

	return buf;
}

//--------------------------------------------------------------------------------------------
/**
 * ポケモンリスト作成
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StagePokeListMake( FRONTIER_MONITOR_WORK * wk )
{
	FRONTIER_EX_SAVEDATA * fes;
	LOAD_RESULT	load_ret;
	u16 * dat;
	u32	max;
	u32	win;
	u16	i, j;

	// フロンティア外部データのロード
	fes = FrontierEx_Load( wk->sv, HEAPID_WORLD, &load_ret );

	if( load_ret == LOAD_RESULT_OK ){
		for( i=0; i<STAGE_STR_INPUT_MAX; i++ ){
			dat = SortDataLoad( i, &max );
			wk->st_pokelist[i].list = sys_AllocMemory( HEAPID_FRONTIER_MONITOR, sizeof(u16)*max );
			for( j=0; j<max; j++ ){
				win = FrontierEx_StageRenshou_Get(
						wk->sv, fes, StageScr_GetExMaxWinRecordID(wk->type), dat[j] );
				if( win != 0 ){
					wk->st_pokelist[i].list[wk->st_pokelist[i].max] = dat[j];
					wk->st_pokelist[i].max++;
				}
			}
			sys_FreeMemoryEz( dat );
		}
	}

	if( fes != NULL ){
		sys_FreeMemoryEz( fes );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * ポケモンリスト解放
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StagePokeListFree( FRONTIER_MONITOR_WORK * wk )
{
	u32	i;

	for( i=0; i<STAGE_STR_INPUT_MAX; i++ ){
		if( wk->st_pokelist[i].list != NULL ){
			sys_FreeMemoryEz( wk->st_pokelist[i].list );
		}
	}
}

//--------------------------------------------------------------------------------------------
/**
 * メッセージウィンドウ読み込み
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StageMsgWinLoad( FRONTIER_MONITOR_WORK * wk )
{
	TalkWinGraphicSet(
		wk->bgl, BFM_FRAME_WIN_S, SUB_MAGWIN_CGX, BFM_MSGWIN_PAL_S,
		CONFIG_GetWindowType(wk->config), HEAPID_FRONTIER_MONITOR );

	TalkFontPaletteLoad( PALTYPE_SUB_BG, BFM_MSGFONT_PAL_S * 32, HEAPID_FRONTIER_MONITOR );
}

//--------------------------------------------------------------------------------------------
/**
 * 上画面メッセージ表示
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StageMsgPut( FRONTIER_MONITOR_WORK * wk )
{
	BmpTalkWinWrite(
		&wk->bmpwin[BS_BMPWIN_INFO], WINDOW_TRANS_OFF, SUB_MAGWIN_CGX, BFM_MSGWIN_PAL_S );

	GF_BGL_BmpWinDataFill( &wk->bmpwin[BS_BMPWIN_INFO], FCOL_WHITE );

	StrPrint(
		wk, BS_BMPWIN_INFO, msg_bf_seiseki_list35,
		0, 0, FONT_TALK, FCOL_W_BLACK, STRPRINT_MODE_LEFT );

	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BS_BMPWIN_INFO] );
}

//--------------------------------------------------------------------------------------------
/**
 * 上画面メッセージ非表示
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StageMsgOff( FRONTIER_MONITOR_WORK * wk )
{
	BmpTalkWinClear( &wk->bmpwin[BS_BMPWIN_INFO], WINDOW_TRANS_OFF );
	GF_BGL_LoadScreenV_Req( wk->bgl, BFM_FRAME_WIN_S );
}


//--------------------------------------------------------------------------------------------
/**
 * 五十音入力ページ・イニシャル表示
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StageInputStrWrite( FRONTIER_MONITOR_WORK * wk )
{
	u16	i, j;

	for( i=0; i<NELEMS(InitialStrPosTbl); i++ ){
		j = InitialStrPosTbl[i];
		StrPrint(
			wk, BS_BMPWIN_SEARCH_AREA, msg_search_initial_01 + i,
			STAGE_STR_INPUT_PX + j / STAGE_STR_INPUT_Y_MAX * STAGE_STR_INPUT_SY,
			STAGE_STR_INPUT_PY + j % STAGE_STR_INPUT_Y_MAX * STAGE_STR_INPUT_SY,
			FONT_TOUCH, FCOL_TOUCH, STRPRINT_MODE_CENTER );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * 五十音入力ページ・カーソル移動
 *
 * @param	wk		成績画面ワーク
 * @param	pos		カーソル位置
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StageInputStrCursorPut( FRONTIER_MONITOR_WORK * wk, int pos )
{
	const POINTER_WORK * pw;
	u8	x, y;

	pw = CURSORMOVE_PointerWorkGet( wk->cmwk, pos );
	PointerWkPosGet( pw, &x, &y );

	ObjPosSet( wk, FM_OBJ_RET_CURSOR, x, y );
	if( pos == STAGE_INPUT_RET_CMWK_ID ){
		ObjAnmSet( wk, FM_OBJ_RET_CURSOR, 1 );
	}else{
		ObjAnmSet( wk, FM_OBJ_RET_CURSOR, 2 );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * 五十音入力ページ・カーソル移動ワーク初期化
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StageInputStrCursorMoveInit( FRONTIER_MONITOR_WORK * wk )
{
	wk->cmwk = CURSORMOVE_Create(
				SearchNameHitTbl,
				SearchNameKeyTbl,
				&SearchNameCallBack,
				wk,
				TRUE,
				wk->stpos,
				HEAPID_FRONTIER_MONITOR );

	StageInputStrCursorPut( wk, wk->stpos );
}

//--------------------------------------------------------------------------------------------
/**
 * 五十音入力ページ・カーソルが移動したときのコールバック関数
 *
 * @param	work		成績画面ワーク
 * @param	now_pos		現在のカーソル位置
 * @param	old_pos		前回のカーソル位置
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StageInputStrCallBack_Move( void * work, int now_pos, int old_pos )
{
	StageInputStrCursorPut( work, now_pos );
}

//--------------------------------------------------------------------------------------------
/**
 * 五十音入力ページ・タッチしたときのコールバック関数
 *
 * @param	work		成績画面ワーク
 * @param	now_pos		現在のカーソル位置
 * @param	old_pos		前回のカーソル位置
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StageInputStrCallBack_Touch( void * work, int now_pos, int old_pos )
{
	StageInputStrCursorPut( work, now_pos );
}

//--------------------------------------------------------------------------------------------
/**
 * 五十音入力ページ・イニシャルボタンアニメ設定
 *
 * @param	wk		成績画面ワーク
 * @param	pos		位置
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StageStrButtonAnmSet( FRONTIER_MONITOR_WORK * wk, u32 pos )
{
	wk->btn_mode = BTN_ANM_MODE_BG;
	wk->btn_id   = BFM_FRAME_BG;
	wk->btn_pal1 = 2;
	wk->btn_pal2 = 0;

	pos = InitialStrPosTbl[pos];

	wk->btn_px = SEARCH_NAME_PX / 8 + pos / SEARCH_NAME_MY * ( STAGE_STR_INPUT_SX / 8 );
	wk->btn_py = SEARCH_NAME_PY / 8 + pos % SEARCH_NAME_MY * ( STAGE_STR_INPUT_SY / 8 ) + 32;
	wk->btn_sx = 2;
	wk->btn_sy = 2;

	wk->btn_seq = 0;
	wk->btn_cnt = 0;
}

//--------------------------------------------------------------------------------------------
/**
 * 五十音入力ページ・カーソル移動メイン
 *
 * @param	wk		成績画面ワーク
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
static u8 StageStrSelectMain( FRONTIER_MONITOR_WORK * wk )
{
	u32	ret = CURSORMOVE_Main(wk->cmwk);

	switch( ret ){
	case STAGE_INPUT_RET_CMWK_ID:
	case CURSORMOVE_CANCEL:			// キャンセル
		Snd_SePlay( SEQ_SE_DP_DECIDE );
		RetButtonAnmSet( wk );
		StageExit( wk );
		wk->next_seq = MAINSEQ_END;
		return MAINSEQ_BUTTON_ANM;

	case CURSORMOVE_CURSOR_MOVE:	// 移動
		Snd_SePlay( SEQ_SE_DP_SELECT );
		break;

	case CURSORMOVE_CURSOR_ON:		// カーソル表示
	case CURSORMOVE_NONE:			// 動作なし
		break;

/*
	case CURSORMOVE_CANCEL:			// キャンセル
		Snd_SePlay( SEQ_SE_DP_DECIDE );
		StageExit( wk );
		return MAINSEQ_END;
*/

	default:
		if( wk->st_pokelist[ret].max == 0 ){
			Snd_SePlay( SEQ_SE_DP_CUSTOM06 );
			break;
		}
		Snd_SePlay( SEQ_SE_DP_DECIDE );
		OS_Printf( "pokelist max = %d\n", wk->st_pokelist[ret].max );
		wk->stpos = ret;
		wk->stmons = 0;
		wk->stscr = 0;
		wk->stscr_max = (wk->st_pokelist[ret].max-1) / STAGE_POKESEL_MAX;
		StageStrButtonAnmSet( wk, wk->stpos );
		wk->next_seq = MAINSEQ_STAGE_POKE_INIT;
		return MAINSEQ_BUTTON_ANM;
	}

	return MAINSEQ_STAGE_STR_SELECT;
}

//--------------------------------------------------------------------------------------------
/**
 * 五十音ページ・ボタンON/OFF設定
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StageStrInputButtonInit( FRONTIER_MONITOR_WORK * wk )
{
	u32	i;

	for( i=0; i<STAGE_STR_INPUT_MAX; i++ ){
		if( wk->st_pokelist[i].max == 0 ){
			StageStrButtonAnmSet( wk, i );
			GF_BGL_ScrPalChange(
				wk->bgl, BFM_FRAME_BG,
				wk->btn_px, wk->btn_py, wk->btn_sx, wk->btn_sy, 1 );
//			CURSORMOVE_MoveTableBitOff( wk->cmwk, i );
		}
	}
	GF_BGL_LoadScreenV_Req( wk->bgl, BFM_FRAME_BG );
}


//--------------------------------------------------------------------------------------------
/**
 * ポケモン選択ページ・カーソル移動
 *
 * @param	wk		成績画面ワーク
 * @param	pos		カーソル位置
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StagePokeSelCursorPut( FRONTIER_MONITOR_WORK * wk, int pos )
{
	const POINTER_WORK * pw;
	u8	x, y;

	pw = CURSORMOVE_PointerWorkGet( wk->cmwk, pos );
	PointerWkPosGet( pw, &x, &y );

	ObjPosSet( wk, FM_OBJ_RET_CURSOR, x, y );
	if( pos == STAGE_POKESEL_MAX ){
		ObjAnmSet( wk, FM_OBJ_RET_CURSOR, 1 );
	}else{
		ObjAnmSet( wk, FM_OBJ_RET_CURSOR, 3 );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * ポケモン選択ページ・カーソル移動ワーク初期化
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StagePokeSelCursorMoveInit( FRONTIER_MONITOR_WORK * wk )
{
	u32	pos = wk->stmons;

	wk->cmwk = CURSORMOVE_Create(
				StagePokeSelHitTbl,
				StagePokeSelKeyTbl,
				&StagePokeSelCallBack,
				wk,
				TRUE,
				pos,
				HEAPID_FRONTIER_MONITOR );

	StagePokeSelCursorPut( wk, pos );
}

//--------------------------------------------------------------------------------------------
/**
 * ポケモン選択ページ・カーソルが移動したときのコールバック関数
 *
 * @param	work		成績画面ワーク
 * @param	now_pos		現在のカーソル位置
 * @param	old_pos		前回のカーソル位置
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StagePokeSelCallBack_Move( void * work, int now_pos, int old_pos )
{
	StagePokeSelCursorPut( work, now_pos );
}

//--------------------------------------------------------------------------------------------
/**
 * ポケモン選択ページ・タッチしたときのコールバック関数
 *
 * @param	work		成績画面ワーク
 * @param	now_pos		現在のカーソル位置
 * @param	old_pos		前回のカーソル位置
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StagePokeSelCallBack_Touch( void * work, int now_pos, int old_pos )
{
	StagePokeSelCursorPut( work, now_pos );
}


//--------------------------------------------------------------------------------------------
/**
 * ポケモン選択ページ・ポケモンボタンアニメ設定
 *
 * @param	wk		成績画面ワーク
 * @param	pos		位置
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StagePokeSelButtonAnmSet( FRONTIER_MONITOR_WORK * wk, u32 pos )
{
	wk->btn_mode = BTN_ANM_MODE_BG;
	wk->btn_id   = BFM_FRAME_BG;
	wk->btn_pal1 = 2;
	wk->btn_pal2 = 0;

	pos = InitialStrPosTbl[pos];

	wk->btn_px = STAGE_POKESEL_BUTTON_PX + STAGE_POKESEL_BUTTON_SPC_X * ( pos % 2 );
	wk->btn_py = STAGE_POKESEL_BUTTON_PY + STAGE_POKESEL_BUTTON_SPC_Y * ( pos / 2 );
	wk->btn_sx = STAGE_POKESEL_BUTTON_SX;
	wk->btn_sy = STAGE_POKESEL_BUTTON_SY;

	wk->btn_seq = 0;
	wk->btn_cnt = 0;
}

//--------------------------------------------------------------------------------------------
/**
 * ポケモン選択ページ・スクロールボタンアニメ設定
 *
 * @param	wk		成績画面ワーク
 * @param	px		X座標
 * @param	py		Y座標
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StagePokeScrollButtonAnmSet( FRONTIER_MONITOR_WORK * wk, u8 px, u8 py )
{
	wk->btn_mode = BTN_ANM_MODE_BG;
	wk->btn_id   = BFM_FRAME_BG;
	wk->btn_pal1 = 2;
	wk->btn_pal2 = 0;

	wk->btn_px = px;
	wk->btn_py = py;
	wk->btn_sx = 4;
	wk->btn_sy = 4;

	wk->btn_seq = 0;
	wk->btn_cnt = 0;
}

//--------------------------------------------------------------------------------------------
/**
 * ポケモン選択ページ・カーソル移動メイン
 *
 * @param	wk		成績画面ワーク
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
static u8 StagePokeSelMain( FRONTIER_MONITOR_WORK * wk )
{
	u32	ret = CURSORMOVE_Main(wk->cmwk);

	switch( ret ){
	case STAGE_POKESEL_MAX:
	case CURSORMOVE_CANCEL:			// キャンセル
		Snd_SePlay( SEQ_SE_DP_DECIDE );
		RetButtonAnmSet( wk );
		wk->next_seq = MAINSEQ_STAGE_STR_INIT;
		return MAINSEQ_BUTTON_ANM;

	case CURSORMOVE_CURSOR_ON:		// カーソル表示
		break;

	case CURSORMOVE_CURSOR_MOVE:	// 移動
		Snd_SePlay( SEQ_SE_DP_SELECT );
		break;

	case CURSORMOVE_NONE:			// 動作なし
		switch( CURSORMOVE_PosGet(wk->cmwk) ){
		case 0:
		case 2:
		case 4:
		case 6:
			if( sys.trg & PAD_KEY_LEFT ){
				if( wk->stscr_max != 0 ){
					wk->stscr--;
					if( wk->stscr < 0 ){
						wk->stscr = wk->stscr_max;
					}
					Snd_SePlay( SEQ_SE_DP_SELECT );
					StagePokeNamePut( wk );
					StagePokePagePut( wk );
//					StageArrowChange( wk );
				}
			}
			break;
		case 1:
		case 3:
		case 5:
		case 7:
			if( sys.trg & PAD_KEY_RIGHT ){
				if( wk->stscr_max != 0 ){
					wk->stscr++;
					if( wk->stscr > wk->stscr_max ){
						wk->stscr = 0;
					}
					Snd_SePlay( SEQ_SE_DP_SELECT );
					StagePokeNamePut( wk );
					StagePokePagePut( wk );
//					StageArrowChange( wk );
				}
			}
			break;
		}
		break;

/*
	case CURSORMOVE_CANCEL:			// キャンセル
		Snd_SePlay( SEQ_SE_DP_DECIDE );
		return MAINSEQ_STAGE_STR_INIT;
*/

	default:
		if( (wk->stscr*STAGE_POKESEL_MAX+ret) >= wk->st_pokelist[wk->stpos].max ){
			Snd_SePlay( SEQ_SE_DP_CUSTOM06 );
			break;
		}
		wk->stmons = ret;
		Snd_SePlay( SEQ_SE_DP_DECIDE );
		StagePokeSelButtonAnmSet( wk, ret );
		wk->next_seq = MAINSEQ_STAGE_RESULT_INIT;
		return MAINSEQ_BUTTON_ANM;
	}

	// スクロール矢印
	switch( GF_TP_RectHitTrg( StagePokeSelArrowHitTbl ) ){
	case 0:
		if( wk->stscr_max != 0 ){
			wk->stscr--;
			if( wk->stscr < 0 ){
				wk->stscr = wk->stscr_max;
			}
			Snd_SePlay( SEQ_SE_DP_SELECT78 );
//			StagePokeNamePut( wk );
//			StagePokePagePut( wk );
			StagePokeScrollButtonAnmSet( wk, 34, 52 );
			wk->next_seq = MAINSEQ_STAGE_POKE_SEL_CHANGE;
			return MAINSEQ_BUTTON_ANM;
		}
		break;

	case 1:
		if( wk->stscr_max != 0 ){
			wk->stscr++;
			if( wk->stscr > wk->stscr_max ){
				wk->stscr = 0;
			}
			Snd_SePlay( SEQ_SE_DP_SELECT78 );
//			StagePokeNamePut( wk );
//			StagePokePagePut( wk );
			StagePokeScrollButtonAnmSet( wk, 38, 52 );
			wk->next_seq = MAINSEQ_STAGE_POKE_SEL_CHANGE;
			return MAINSEQ_BUTTON_ANM;
		}
		break;
	}

	return MAINSEQ_STAGE_POKE_SELECT;
}

//--------------------------------------------------------------------------------------------
/**
 * ポケモン選択ページ切り替え
 *
 * @param	wk		成績画面ワーク
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
static u8 StagePokeSelPageChange( FRONTIER_MONITOR_WORK * wk )
{
	StagePokeNamePut( wk );
	StagePokePagePut( wk );
//	StageArrowChange( wk );
	return MAINSEQ_STAGE_POKE_SELECT;
}

//--------------------------------------------------------------------------------------------
/**
 * ポケモン選択ページ・ポケモン名表示
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StagePokeNamePut( FRONTIER_MONITOR_WORK * wk )
{
	u32	winID;
	u16	start;
	u8	pal;
	u8	i;

	if( wk->stswap == 0 ){
		winID = BS_BMPWIN_POKE01;
	}else{
		winID = BS_BMPWIN_POKE11;
	}

	start = wk->stscr * STAGE_POKESEL_MAX;

	for( i=0; i<STAGE_POKESEL_MAX; i++ ){
		GF_BGL_BmpWinDataFill( &wk->bmpwin[winID+i], 0 );
		if( wk->st_pokelist[wk->stpos].max > (start+i) ){
			FrontierMonitor_PokeName( wk, wk->st_pokelist[wk->stpos].list[start+i] );
			ExStrPrint(
				wk, winID+i, msg_bf_seiseki_03_01,
				GF_BGL_BmpWinGet_SizeX(&wk->bmpwin[winID+i])*8/2, 0,
				FONT_TOUCH, FCOL_TOUCH, STRPRINT_MODE_CENTER );
			pal = 0;
		}else{
			pal = 1;
		}
		GF_BGL_BmpWinOnVReq( &wk->bmpwin[winID+i] );

		StagePokeSelButtonAnmSet( wk, i );
		GF_BGL_ScrPalChange(
			wk->bgl, BFM_FRAME_BG,
			wk->btn_px, wk->btn_py, wk->btn_sx, wk->btn_sy, pal );
	}

	GF_BGL_LoadScreenV_Req( wk->bgl, BFM_FRAME_BG );

	wk->stswap ^= 1;
}

//--------------------------------------------------------------------------------------------
/**
 * ポケモン選択ページ・ポケモン名非表示
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StagePokeNameOff( FRONTIER_MONITOR_WORK * wk )
{
	u32	i;

	for( i=BS_BMPWIN_POKE01; i<=BS_BMPWIN_POKE11; i++ ){
		GF_BGL_BmpWinOffVReq( &wk->bmpwin[i] );
	}
	GF_BGL_BmpWinOffVReq( &wk->bmpwin[BS_BMPWIN_INITIAL] );
	GF_BGL_BmpWinOffVReq( &wk->bmpwin[BS_BMPWIN_PAGE] );
}

//--------------------------------------------------------------------------------------------
/**
 * ポケモン選択ページ・イニシャル表示
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StagePokeInitialPut( FRONTIER_MONITOR_WORK * wk )
{
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BS_BMPWIN_INITIAL], 0 );

	StrPrint(
		wk, BS_BMPWIN_INITIAL, msg_search_initial_01 + wk->stpos,
		GF_BGL_BmpWinGet_SizeX(&wk->bmpwin[BS_BMPWIN_INITIAL])*8/2,
		0,
		FONT_TOUCH, FCOL_TOUCH, STRPRINT_MODE_CENTER );

	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BS_BMPWIN_INITIAL] );
}

//--------------------------------------------------------------------------------------------
/**
 * ポケモン選択ページ・ページ表示
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StagePokePagePut( FRONTIER_MONITOR_WORK * wk )
{
	GF_BGL_BmpWinDataFill( &wk->bmpwin[BS_BMPWIN_PAGE], 0 );

	SetNumber( wk, 0, wk->stscr+1 );
	ExStrPrint(
		wk, BS_BMPWIN_PAGE, msg_bf_seiseki_list33,
		STAGE_POKEPAGE_NOW_PX, 0,
		FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	StrPrint(
		wk, BS_BMPWIN_PAGE, msg_bf_seiseki_list34,
		STAGE_POKEPAGE_SRA_PX, 0,
		FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_CENTER );

	SetNumber( wk, 0, wk->stscr_max+1 );
	ExStrPrint(
		wk, BS_BMPWIN_PAGE, msg_bf_seiseki_list33,
		STAGE_POKEPAGE_MAX_PX, 0,
		FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	GF_BGL_BmpWinOnVReq( &wk->bmpwin[BS_BMPWIN_PAGE] );
}


//--------------------------------------------------------------------------------------------
/**
 * 成績ページ・カーソル位置設定
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StageResultCursorInit( FRONTIER_MONITOR_WORK * wk )
{
	ObjPosSet( wk, FM_OBJ_RET_CURSOR, OBJ_RET_BUTTON_PX, OBJ_RET_BUTTON_PY );
	ObjAnmSet( wk, FM_OBJ_RET_CURSOR, 1 );
}

//--------------------------------------------------------------------------------------------
/**
 * 成績ページ・文字表示
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StageResultBmpPut( FRONTIER_MONITOR_WORK * wk )
{
	wk->monsno = wk->st_pokelist[wk->stpos].list[wk->stscr*STAGE_POKESEL_MAX+wk->stmons];
	Stage_SetInfo( wk );
}

//--------------------------------------------------------------------------------------------
/**
 * 成績ページ・文字非表示
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void StageResultBmpOff( FRONTIER_MONITOR_WORK * wk )
{
	GF_BGL_BmpWinOffVReq( &wk->bmpwin[BS_BMPWIN_TITLE] );
	GF_BGL_BmpWinOffVReq( &wk->bmpwin[BS_BMPWIN_ENTRY1] );
	GF_BGL_BmpWinOffVReq( &wk->bmpwin[BS_BMPWIN_BEFORE] );
	GF_BGL_BmpWinOffVReq( &wk->bmpwin[BS_BMPWIN_MAX] );
}